api

package
v0.0.0-...-e2be882 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyUser

func AnyUser() map[string]struct{}

AnyUser is a predefined validator for any value.

func Contains

func Contains(arg ...string) map[string]struct{}

Contains is a predefined validator for the argument being one of the given values.

func Counter

func Counter(limit int) func(trade *model.TradeSignal, numberOfTrades int) bool

func NonStop

func NonStop(trade *model.TradeSignal, numberOfTrades int) bool

func Reply

func Reply(private Index, user User, message *Message, err error)

Reply sends a reply message based on the given error to the user.

func Until

func Until(time time.Time) func(trade *model.TradeSignal, numberOfTrades int) bool

Types

type Block

type Block struct {
	// Action block.Signal <- api.Signal{}
	Action chan Signal
	// ReAction	<-block.ReAction
	ReAction chan Signal
}

Block allows 2 processes to sync

func NewBlock

func NewBlock() Block

type Client

type Client interface {
	Trades(process <-chan Signal) (model.TradeSource, error)
}

Client exposes the low level interface for interacting with a trade source.

type Command

type Command struct {
	ID      int
	User    string
	Content string
}

Command is the definitions of metadata for a command.

func CommandFromMessage

func CommandFromMessage(id int, user, cmd string, opts ...string) Command

CommandFromMessage parses a command from a message details.

func NewCommand

func NewCommand(id int, user string, cmd ...string) Command

NewCommand parses a command from a message details.

func (Command) Validate

func (c Command) Validate(user map[string]struct{}, exe map[string]struct{}, args ...Validator) (string, error)

Validate validates the command with the given arguments.

type Condition

type Condition func(trade *model.TradeSignal, numberOfTrades int) bool

Condition defines a boundary condition to stop execution based on the consumed trades.

type ConsumerKey

type ConsumerKey struct {
	ID     string
	Key    string
	Prefix string
}

ConsumerKey is the internal consumer key for indexing and managing consumers.

type Exchange

type Exchange interface {
	OpenPositions(ctx context.Context) (*model.PositionBatch, error)
	OpenOrder(order *model.TrackedOrder) (*model.TrackedOrder, []string, error)
	Balance(ctx context.Context, priceMap map[model.Coin]model.CurrentPrice) (map[model.Coin]model.Balance, error)
	Pairs(ctx context.Context) map[string]Pair
	CurrentPrice(ctx context.Context) (map[model.Coin]model.CurrentPrice, error)
}

Exchange allows interaction with the exchange for submitting and closing positions and trades.

type ExchangeName

type ExchangeName string

ExchangeName defines the name of the exchange

type Index

type Index string

Index is the identifier for the user communication channel

type Message

type Message struct {
	Text  string
	Reply int
	Time  time.Time
}

Message defines a message that should be sent to the user or group.

func ErrorMessage

func ErrorMessage(txt string) *Message

ErrorMessage creates a new error message.

func NewMessage

func NewMessage(txt string) *Message

NewMessage creates a new message.

func (*Message) AddLine

func (m *Message) AddLine(txt string) *Message

AddLine adds a line argument to the message.

func (*Message) ReferenceTime

func (m *Message) ReferenceTime(t time.Time) *Message

ReferenceTime adds a reference time to the message. This is especially useful for back-testing adn debugging.

func (*Message) ReplyTo

func (m *Message) ReplyTo(msgID int) *Message

ReplyTo defines a message id that this message refers to.

type Pair

type Pair struct {
	Coin model.Coin
}

Pair defines a coin trading pair.

type Processor

type Processor func(in <-chan *model.TradeSignal, out chan<- *model.TradeSignal)

Processor defines the processing model of input and output channels for trades. Each processor will trigger the next one, when pushing the trade to the output channel. TODO : add load and save functionality for processors interface to allow saving and loading state.

type Query

type Query struct {
	Coin  model.Coin
	Index string
}

Query is the trades query object.

type Signal

type Signal struct {
	Name    string
	ID      string
	Coin    model.Coin
	Content interface{}
	Time    time.Time
}

Signal is a generic struct used to trigger actions on other processes. it can hold metadata information , but for now we leave it empty.

func NewSignal

func NewSignal(name string) *Signal

NewSignal creates a new action with the given name.

func (*Signal) Create

func (a *Signal) Create() Signal

Create returns an immutable instance of the action

func (*Signal) ForCoin

func (a *Signal) ForCoin(coin model.Coin) *Signal

ForCoin assigns a coin to the action

func (*Signal) WithContent

func (a *Signal) WithContent(s interface{}) *Signal

WithContent adds content to the action. This would indicate an actionable event. The content should be de-coded by using the the name of the action.

func (*Signal) WithID

func (a *Signal) WithID(id string) *Signal

WithID assigns an id to the action

type StrategyProcessor

type StrategyProcessor func(u User, e Exchange) Processor

StrategyProcessor defines a processing logic for a strategy

type Trigger

type Trigger struct {
	ID          string
	Key         ConsumerKey
	Default     []string
	Description string
	Timeout     time.Duration
}

Trigger wraps a trigger func into a re-usable object.

func NewTrigger

func NewTrigger(key ConsumerKey) *Trigger

NewTrigger creates a new trigger.

func (*Trigger) WithDefaults

func (t *Trigger) WithDefaults(defaults ...string) *Trigger

WithDefaults specifies default argument for the auto-callback.

func (*Trigger) WithDescription

func (t *Trigger) WithDescription(desc string) *Trigger

WithDescription allows to specify a custom description for the trigger.

func (*Trigger) WithID

func (t *Trigger) WithID(id string) *Trigger

WithID allows to specify a custom ID for the trigger.

func (*Trigger) WithTimeout

func (t *Trigger) WithTimeout(timeout time.Duration) *Trigger

WithTimeout allows the user to specify a custom timeout for the trigger.

type TriggerFunc

type TriggerFunc func(command Command) (string, error)

TriggerFunc defines an execution logic based on the command and options arguments.

type User

type User interface {
	// Run starts the user interface implementation and initialises any external connections.
	Run(ctx context.Context) error
	// Listen returns a channel of commands to the caller to interact with the user.
	// the caller needs to provide a unique subscription key.
	// additionally the caller can define a prefix to avoid being spammed with messages not relevant to them.
	Listen(key, prefix string) <-chan Command
	// Send sends a message to the user adn returns the message ID
	Send(channel Index, message *Message, trigger *Trigger) int
	// AddUser adds the given chatID for the specified user name
	AddUser(channel Index, user string, chatID int64) error
}

User defines an external interface for exchanging information and sharing control with the user(s)

type Validator

type Validator func(string) error

Validator is a validation function that checks the string for the given type.

func Any

func Any(v *string) Validator

Any is effectively no validator, as it allows any argument.

func Float

func Float(f *float64) Validator

Float is a predefined Validator checking that the argument is a float. it passes the reference to the value to the given interface argument. it allows for emopty value, and interprets it as zero

func Int

func Int(d *int) Validator

Int is a predefined Validator checking that the argument is an int. it passes the reference to the value to the given interface argument.

func NotEmpty

func NotEmpty(v *string) Validator

NotEmpty is a predefined Validator that checks if the argument is empty.

func OneOf

func OneOf(v *string, args ...string) Validator

OneOf is a predefined Validator checking that the value is one of the provided arguments. it passes the reference to the value to the given interface argument.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL