model

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SideTypeBuy  SideType = "BUY"
	SideTypeSell SideType = "SELL"

	OrderTypeLimit           OrderType = "LIMIT"
	OrderTypeMarket          OrderType = "MARKET"
	OrderTypeLimitMaker      OrderType = "LIMIT_MAKER"
	OrderTypeStopLoss        OrderType = "STOP_LOSS"
	OrderTypeStopLossLimit   OrderType = "STOP_LOSS_LIMIT"
	OrderTypeTakeProfit      OrderType = "TAKE_PROFIT"
	OrderTypeTakeProfitLimit OrderType = "TAKE_PROFIT_LIMIT"

	OrderStatusTypeNew             OrderStatusType = "NEW"
	OrderStatusTypePartiallyFilled OrderStatusType = "PARTIALLY_FILLED"
	OrderStatusTypeFilled          OrderStatusType = "FILLED"
	OrderStatusTypeCanceled        OrderStatusType = "CANCELED"
	OrderStatusTypePendingCancel   OrderStatusType = "PENDING_CANCEL"
	OrderStatusTypeRejected        OrderStatusType = "REJECTED"
	OrderStatusTypeExpired         OrderStatusType = "EXPIRED"
)

Functions

func NumDecPlaces

func NumDecPlaces(v float64) int64

NumDecPlaces returns the number of decimal places of a float64

Types

type Account

type Account struct {
	Balances []Balance
}

func (Account) Balance

func (a Account) Balance(assetTick, quoteTick string) (Balance, Balance)

func (Account) Equity

func (a Account) Equity() float64

type AssetInfo

type AssetInfo struct {
	BaseAsset  string
	QuoteAsset string

	MinPrice    float64
	MaxPrice    float64
	MinQuantity float64
	MaxQuantity float64
	StepSize    float64
	TickSize    float64

	QuotePrecision     int
	BaseAssetPrecision int
}

type Balance

type Balance struct {
	Asset    string
	Free     float64
	Lock     float64
	Leverage float64
}

type Candle

type Candle struct {
	Pair      string
	Time      time.Time
	UpdatedAt time.Time
	Open      float64
	Close     float64
	Low       float64
	High      float64
	Volume    float64
	Complete  bool

	// Aditional collums from CSV inputs
	Metadata map[string]float64
}

func (Candle) Empty

func (c Candle) Empty() bool

func (Candle) Less

func (c Candle) Less(j Item) bool

func (Candle) ToHeikinAshi

func (c Candle) ToHeikinAshi(ha *HeikinAshi) Candle

func (Candle) ToSlice

func (c Candle) ToSlice(precision int) []string

type Dataframe

type Dataframe struct {
	Pair string

	Close  Series[float64]
	Open   Series[float64]
	High   Series[float64]
	Low    Series[float64]
	Volume Series[float64]

	Time       []time.Time
	LastUpdate time.Time

	// Custom user metadata
	Metadata map[string]Series[float64]
}

func (Dataframe) Sample

func (df Dataframe) Sample(positions int) Dataframe

type Discard

type Discard struct {
	Pair     string    `json:"pair"`
	Side     SideType  `json:"side"`
	Quantity float64   `json:"quantity"`
	AfterID  int64     `json:"after_id"`
	At       time.Time `json:"at"`
}

Discard is a position of the bot the order controller found gone from the exchange and dropped without a fill, eg: closed outside the bot (by hand in the terminal, by a stop out): its side and its quantity, and where, after the fill of the pair of AfterID, the last one it had settled, and when. The replay of the filled orders after a restart drops it again at the same place, rather than settling the trades after it against it.

func (Discard) Key

func (d Discard) Key() string

Key names the discard, eg: XAUUSDm:6001, its pair and the fill after it.

func (Discard) Same

func (d Discard) Same(other Discard) bool

Same reports whether d and other are the same discard: of the same pair, after the same fill, as they are kept once.

type HeikinAshi

type HeikinAshi struct {
	PreviousHACandle Candle
}

func NewHeikinAshi

func NewHeikinAshi() *HeikinAshi

func (*HeikinAshi) CalculateHeikinAshi

func (ha *HeikinAshi) CalculateHeikinAshi(c Candle) Candle

type Item

type Item interface {
	Less(Item) bool
}

type Order

type Order struct {
	ID         int64           `db:"id" json:"id" gorm:"primaryKey,autoIncrement"`
	ExchangeID int64           `db:"exchange_id" json:"exchange_id"`
	Pair       string          `db:"pair" json:"pair"`
	Side       SideType        `db:"side" json:"side"`
	Type       OrderType       `db:"type" json:"type"`
	Status     OrderStatusType `db:"status" json:"status"`
	Price      float64         `db:"price" json:"price"`
	Quantity   float64         `db:"quantity" json:"quantity"`

	// Fee charged by the exchange to fill the order, in quote currency.
	Fee float64 `db:"fee" json:"fee"`

	CreatedAt time.Time `db:"created_at" json:"created_at"`
	UpdatedAt time.Time `db:"updated_at" json:"updated_at"`

	// OCO Orders only
	Stop    *float64 `db:"stop" json:"stop"`
	GroupID *int64   `db:"group_id" json:"group_id"`

	// Internal use (Plot)
	RefPrice    float64 `json:"ref_price" gorm:"-"`
	Profit      float64 `json:"profit" gorm:"-"`
	ProfitValue float64 `json:"profit_value" gorm:"-"`
	Candle      Candle  `json:"-" gorm:"-"`
}

func (Order) Finite

func (o Order) Finite() (Order, []string)

Finite returns the order with its numbers that aren't finite, which JSON can't write, eg: the profit of a fill without a price, set to 0, and their JSON names. Its Stop is copied when set to 0.

func (Order) String

func (o Order) String() string

func (Order) Supersedes

func (o Order) Supersedes(prev Order) bool

Supersedes reports whether o, a state of the order of prev, replaces prev written after it: a final status (see Final) is never replaced by an open one, and replaces an open one whatever their UpdatedAt (the one of a fill is the time of the broker, the one of a move the clock of the agent); else o is not older than prev, to the microsecond a database keeps, the same state written again replacing it.

type OrderStatusType

type OrderStatusType string

func (OrderStatusType) Final

func (s OrderStatusType) Final() bool

Final reports whether the status ends the order for good: filled, canceled, rejected or expired.

type OrderType

type OrderType string

type PriorityQueue

type PriorityQueue struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PriorityQueue is a heap of items, the least first (see Item.Less), safe for concurrent use. PopLock hands its items to a consumer as they are pushed.

func NewPriorityQueue

func NewPriorityQueue(data []Item) *PriorityQueue

func (*PriorityQueue) Len

func (q *PriorityQueue) Len() int

func (*PriorityQueue) Peek

func (q *PriorityQueue) Peek() Item

func (*PriorityQueue) Pop

func (q *PriorityQueue) Pop() Item

func (*PriorityQueue) PopLock

func (q *PriorityQueue) PopLock(ctx context.Context) <-chan Item

PopLock returns a channel handing the items of the queue, the ones pushed before included, as they come, until ctx is done, when it is closed. A single goroutine pops them, one at a time, as the consumer takes the previous one: two items queued together come out in their order, eg: the close of a candle before the next candle in progress, never the other way around, as when each push popped an item in a goroutine of its own racing the others to the channel. The item popped and not taken by the time ctx is done goes back to the queue. Called again, it returns the same channel: the items have one consumer.

func (*PriorityQueue) Push

func (q *PriorityQueue) Push(item Item)

type Series

type Series[T constraints.Ordered] []T

Series is a time series of values

func (Series[T]) Cross

func (s Series[T]) Cross(ref Series[T]) bool

Cross returns true if the last value of the series is greater than the last value of the reference series or less than the last value of the reference series

func (Series[T]) Crossover

func (s Series[T]) Crossover(ref Series[T]) bool

Crossover returns true if the last value of the series is greater than the last value of the reference series

func (Series[T]) Crossunder

func (s Series[T]) Crossunder(ref Series[T]) bool

Crossunder returns true if the last value of the series is less than the last value of the reference series

func (Series[T]) Last

func (s Series[T]) Last(position int) T

Last returns the last value of the series given a past index position

func (Series[T]) LastValues

func (s Series[T]) LastValues(size int) []T

LastValues returns the last values of the series given a size

func (Series[T]) Length

func (s Series[T]) Length() int

Length returns the number of values in the series

func (Series[T]) Values

func (s Series[T]) Values() []T

Values returns the values of the series

type Settings

type Settings struct {
	Pairs []string
}

Settings are the pairs the engine trades. The agents relay their notices to the Telegram of the controller: the engine has none of its own.

type SideType

type SideType string

Jump to

Keyboard shortcuts

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