Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
NumDecPlaces returns the number of decimal places of a float64
Types ¶
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) ToHeikinAshi ¶
func (c Candle) ToHeikinAshi(ha *HeikinAshi) Candle
type 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.
type HeikinAshi ¶
type HeikinAshi struct {
PreviousHACandle Candle
}
func NewHeikinAshi ¶
func NewHeikinAshi() *HeikinAshi
func (*HeikinAshi) CalculateHeikinAshi ¶
func (ha *HeikinAshi) CalculateHeikinAshi(c Candle) Candle
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 ¶
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) Supersedes ¶
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 PriorityQueue ¶
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 ¶
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 ¶
Crossover returns true if the last value of the series is greater than the last value of the reference series
func (Series[T]) Crossunder ¶
Crossunder returns true if the last value of the series is less than the last value of the reference series
func (Series[T]) LastValues ¶
LastValues returns the last values of the series given a size