Documentation ¶
Index ¶
- Constants
- type OrderStore
- func (s *OrderStore) Add(orders ...types.Order)
- func (s *OrderStore) AllFilled() bool
- func (s *OrderStore) BindStream(stream types.Stream)
- func (s *OrderStore) Exists(oID uint64) (ok bool)
- func (s *OrderStore) Get(oID uint64) (order types.Order, ok bool)
- func (s *OrderStore) HandleOrderUpdate(order types.Order)
- func (s *OrderStore) NumOfOrders() (num int)
- func (s *OrderStore) Orders() (orders []types.Order)
- func (s *OrderStore) Remove(o types.Order)
- func (s *OrderStore) Update(o types.Order) bool
- type TradeCollector
- func (c *TradeCollector) BindStream(stream types.Stream)
- func (c *TradeCollector) BindStreamForBackground(stream types.Stream)
- func (c *TradeCollector) Emit()
- func (c *TradeCollector) EmitPositionUpdate(position *types.Position)
- func (c *TradeCollector) EmitProfit(trade types.Trade, profit *types.Profit)
- func (c *TradeCollector) EmitRecover(trade types.Trade)
- func (c *TradeCollector) EmitTrade(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value)
- func (c *TradeCollector) OnPositionUpdate(cb func(position *types.Position))
- func (c *TradeCollector) OnProfit(cb func(trade types.Trade, profit *types.Profit))
- func (c *TradeCollector) OnRecover(cb func(trade types.Trade))
- func (c *TradeCollector) OnTrade(...)
- func (c *TradeCollector) OrderStore() *OrderStore
- func (c *TradeCollector) Position() *types.Position
- func (c *TradeCollector) Process() bool
- func (c *TradeCollector) ProcessTrade(trade types.Trade) bool
- func (c *TradeCollector) QueueTrade(trade types.Trade)
- func (c *TradeCollector) Recover(ctx context.Context, ex types.ExchangeTradeHistoryService, symbol string, ...) error
- func (c *TradeCollector) RecoverTrade(td types.Trade) bool
- func (c *TradeCollector) Run(ctx context.Context)
- func (c *TradeCollector) SetPosition(position *types.Position)
- func (c *TradeCollector) TradeStore() *TradeStore
- type TradeFilter
- type TradeStore
- func (s *TradeStore) Add(trades ...types.Trade)
- func (s *TradeStore) BindStream(stream types.Stream)
- func (s *TradeStore) Clear()
- func (s *TradeStore) Exists(oID uint64) (ok bool)
- func (s *TradeStore) Filter(filter TradeFilter)
- func (s *TradeStore) GetAndClear() (trades []types.Trade)
- func (s *TradeStore) GetOrderTrades(o types.Order) (trades []types.Trade)
- func (s *TradeStore) Num() (num int)
- func (s *TradeStore) Prune(curTime time.Time)
- func (s *TradeStore) Trades() (trades []types.Trade)
Constants ¶
const CoolTradePeriod = 1 * time.Hour
const MaximumTradeStoreSize = 1_000
const TradeExpiryTime = 3 * time.Hour
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type OrderStore ¶
type OrderStore struct { Symbol string // RemoveCancelled removes the canceled order when receiving a cancel order update event // It also removes the order even if it's partially filled // by default, only 0 filled canceled order will be removed. RemoveCancelled bool // RemoveFilled removes the fully filled order when receiving a filled order update event RemoveFilled bool // AddOrderUpdate adds the order into the store when receiving an order update when the order does not exist in the current store. AddOrderUpdate bool C chan types.Order // contains filtered or unexported fields }
func NewOrderStore ¶
func NewOrderStore(symbol string) *OrderStore
func (*OrderStore) Add ¶
func (s *OrderStore) Add(orders ...types.Order)
func (*OrderStore) AllFilled ¶
func (s *OrderStore) AllFilled() bool
func (*OrderStore) BindStream ¶
func (s *OrderStore) BindStream(stream types.Stream)
func (*OrderStore) Exists ¶
func (s *OrderStore) Exists(oID uint64) (ok bool)
func (*OrderStore) Get ¶
func (s *OrderStore) Get(oID uint64) (order types.Order, ok bool)
Get a single order from the order store by order ID Should check ok to make sure the order is returned successfully
func (*OrderStore) HandleOrderUpdate ¶
func (s *OrderStore) HandleOrderUpdate(order types.Order)
func (*OrderStore) NumOfOrders ¶
func (s *OrderStore) NumOfOrders() (num int)
func (*OrderStore) Orders ¶
func (s *OrderStore) Orders() (orders []types.Order)
func (*OrderStore) Remove ¶
func (s *OrderStore) Remove(o types.Order)
type TradeCollector ¶
type TradeCollector struct { Symbol string // contains filtered or unexported fields }
func NewTradeCollector ¶
func NewTradeCollector(symbol string, position *types.Position, orderStore *OrderStore) *TradeCollector
func (*TradeCollector) BindStream ¶
func (c *TradeCollector) BindStream(stream types.Stream)
func (*TradeCollector) BindStreamForBackground ¶
func (c *TradeCollector) BindStreamForBackground(stream types.Stream)
BindStreamForBackground bind the stream callback for background processing
func (*TradeCollector) Emit ¶
func (c *TradeCollector) Emit()
Emit triggers the trade processing (position update) If you sent order, and the order store is updated, you can call this method so that trades will be processed in the next round of the goroutine loop
func (*TradeCollector) EmitPositionUpdate ¶
func (c *TradeCollector) EmitPositionUpdate(position *types.Position)
func (*TradeCollector) EmitProfit ¶
func (c *TradeCollector) EmitProfit(trade types.Trade, profit *types.Profit)
func (*TradeCollector) EmitRecover ¶
func (c *TradeCollector) EmitRecover(trade types.Trade)
func (*TradeCollector) EmitTrade ¶
func (c *TradeCollector) EmitTrade(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value)
func (*TradeCollector) OnPositionUpdate ¶
func (c *TradeCollector) OnPositionUpdate(cb func(position *types.Position))
func (*TradeCollector) OnProfit ¶
func (c *TradeCollector) OnProfit(cb func(trade types.Trade, profit *types.Profit))
func (*TradeCollector) OnRecover ¶
func (c *TradeCollector) OnRecover(cb func(trade types.Trade))
func (*TradeCollector) OnTrade ¶
func (c *TradeCollector) OnTrade(cb func(trade types.Trade, profit fixedpoint.Value, netProfit fixedpoint.Value))
func (*TradeCollector) OrderStore ¶
func (c *TradeCollector) OrderStore() *OrderStore
OrderStore returns the order store used by the trade collector
func (*TradeCollector) Position ¶
func (c *TradeCollector) Position() *types.Position
Position returns the position used by the trade collector
func (*TradeCollector) Process ¶
func (c *TradeCollector) Process() bool
Process filters the received trades and see if there are orders matching the trades if we have the order in the order store, then the trade will be considered for the position. profit will also be calculated.
func (*TradeCollector) ProcessTrade ¶
func (c *TradeCollector) ProcessTrade(trade types.Trade) bool
return true when the given trade is added return false when the given trade is not added
func (*TradeCollector) QueueTrade ¶
func (c *TradeCollector) QueueTrade(trade types.Trade)
QueueTrade sends the trade object to the trade channel, so that the goroutine can receive the trade and process in the background.
func (*TradeCollector) Recover ¶
func (c *TradeCollector) Recover( ctx context.Context, ex types.ExchangeTradeHistoryService, symbol string, from time.Time, ) error
func (*TradeCollector) RecoverTrade ¶
func (c *TradeCollector) RecoverTrade(td types.Trade) bool
func (*TradeCollector) Run ¶
func (c *TradeCollector) Run(ctx context.Context)
Run is a goroutine executed in the background Do not use this function if you need back-testing
func (*TradeCollector) SetPosition ¶
func (c *TradeCollector) SetPosition(position *types.Position)
func (*TradeCollector) TradeStore ¶
func (c *TradeCollector) TradeStore() *TradeStore
type TradeFilter ¶
type TradeStore ¶
type TradeStore struct { // any created trades for tracking trades sync.Mutex EnablePrune bool // contains filtered or unexported fields }
func NewTradeStore ¶
func NewTradeStore() *TradeStore
func (*TradeStore) Add ¶
func (s *TradeStore) Add(trades ...types.Trade)
func (*TradeStore) BindStream ¶
func (s *TradeStore) BindStream(stream types.Stream)
func (*TradeStore) Clear ¶
func (s *TradeStore) Clear()
func (*TradeStore) Exists ¶
func (s *TradeStore) Exists(oID uint64) (ok bool)
func (*TradeStore) Filter ¶
func (s *TradeStore) Filter(filter TradeFilter)
Filter filters the trades by a given TradeFilter function
func (*TradeStore) GetAndClear ¶
func (s *TradeStore) GetAndClear() (trades []types.Trade)
func (*TradeStore) GetOrderTrades ¶
func (s *TradeStore) GetOrderTrades(o types.Order) (trades []types.Trade)
GetOrderTrades finds the trades match order id matches to the given order
func (*TradeStore) Num ¶
func (s *TradeStore) Num() (num int)
func (*TradeStore) Prune ¶
func (s *TradeStore) Prune(curTime time.Time)
Prune prunes trades that are older than the expiry time see TradeExpiryTime (3 hours)
func (*TradeStore) Trades ¶
func (s *TradeStore) Trades() (trades []types.Trade)