Documentation ¶
Index ¶
- func SubscribeToExchangeOrderbooks(exchange string) (dispatch.Pipe, error)
- type Base
- func (b *Base) GetAveragePrice(buy bool, amount float64) (float64, error)
- func (b *Base) Process() error
- func (b *Base) SimulateOrder(amount float64, buy bool) *OrderSimulationResult
- func (b *Base) TotalAsksAmount() (amountCollated, total float64)
- func (b *Base) TotalBidsAmount() (amountCollated, total float64)
- func (b *Base) Verify() error
- func (b *Base) WhaleBomb(priceTarget float64, buy bool) (*WhaleBombResult, error)
- type ByPrice
- type Depth
- func (d *Depth) AssignOptions(b *Base)
- func (d *Depth) DeleteBidAskByID(bidUpdts, askUpdts Items, bypassErr bool, lastUpdateID int64, ...) error
- func (d *Depth) Flush()
- func (d *Depth) GetAskLength() int
- func (d *Depth) GetBidLength() int
- func (d *Depth) GetName() string
- func (d *Depth) GetUnsafe() Unsafe
- func (d *Depth) InsertBidAskByID(bidUpdts, askUpdts Items, lastUpdateID int64, lastUpdated time.Time) error
- func (d *Depth) IsFundingRate() bool
- func (d *Depth) IsRestSnapshot() bool
- func (d *Depth) LastUpdateID() int64
- func (d *Depth) LoadSnapshot(bids, asks []Item, lastUpdateID int64, lastUpdated time.Time, ...)
- func (d *Depth) Publish()
- func (d *Depth) Retrieve() *Base
- func (d *Depth) TotalAskAmounts() (liquidity, value float64)
- func (d *Depth) TotalBidAmounts() (liquidity, value float64)
- func (d *Depth) UpdateBidAskByID(bidUpdts, askUpdts Items, lastUpdateID int64, lastUpdated time.Time) error
- func (d *Depth) UpdateBidAskByPrice(bidUpdts, askUpdts Items, maxDepth int, lastUpdateID int64, ...)
- func (d *Depth) UpdateInsertByID(bidUpdts, askUpdts Items, lastUpdateID int64, lastUpdated time.Time) error
- type Exchange
- type Item
- type Items
- type Node
- type OrderSimulationResult
- type Service
- func (s *Service) DeployDepth(exchange string, p currency.Pair, a asset.Item) (*Depth, error)
- func (s *Service) GetDepth(exchange string, p currency.Pair, a asset.Item) (*Depth, error)
- func (s *Service) Retrieve(exchange string, p currency.Pair, a asset.Item) (*Base, error)
- func (s *Service) Update(b *Base) error
- type Unsafe
- type WhaleBombResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Base ¶
type Base struct { Bids Items Asks Items Exchange string Pair currency.Pair Asset asset.Item LastUpdated time.Time LastUpdateID int64 // PriceDuplication defines whether an orderbook can contain duplicate // prices in a payload PriceDuplication bool IsFundingRate bool // VerifyOrderbook allows for a toggle between orderbook verification set by // user configuration, this allows for a potential processing boost but // a potential for orderbook integrity being deminished. VerifyOrderbook bool `json:"-"` // RestSnapshot defines if the depth was applied via the REST protocol thus // an update cannot be applied via websocket mechanics and a resubscription // would need to take place to maintain book integrity RestSnapshot bool // Checks if the orderbook needs ID alignment as well as price alignment IDAlignment bool }
Base holds the fields for the orderbook base
func (*Base) GetAveragePrice ¶
GetAveragePrice finds the average buy or sell price of a specified amount. It finds the nominal amount spent on the total purchase or sell and uses it to find the average price for an individual unit bought or sold
func (*Base) Process ¶
Process processes incoming orderbooks, creating or updating the orderbook list
func (*Base) SimulateOrder ¶
func (b *Base) SimulateOrder(amount float64, buy bool) *OrderSimulationResult
SimulateOrder simulates an order
func (*Base) TotalAsksAmount ¶
TotalAsksAmount returns the total amount of asks and the total orderbook asks value
func (*Base) TotalBidsAmount ¶
TotalBidsAmount returns the total amount of bids and the total orderbook bids value
type Depth ¶
Depth defines a linked list of orderbook items
func DeployDepth ¶
DeployDepth sets a depth struct and returns a depth pointer. This allows for the loading of a new orderbook snapshot and incremental updates via the streaming package.
func (*Depth) AssignOptions ¶
AssignOptions assigns the initial options for the depth instance
func (*Depth) DeleteBidAskByID ¶
func (d *Depth) DeleteBidAskByID(bidUpdts, askUpdts Items, bypassErr bool, lastUpdateID int64, lastUpdated time.Time) error
DeleteBidAskByID deletes a price level by ID
func (*Depth) GetUnsafe ¶
GetUnsafe returns an unsafe orderbook with pointers to the linked list heads.
func (*Depth) InsertBidAskByID ¶
func (d *Depth) InsertBidAskByID(bidUpdts, askUpdts Items, lastUpdateID int64, lastUpdated time.Time) error
InsertBidAskByID inserts new updates
func (*Depth) IsFundingRate ¶
IsFundingRate returns if the depth is a funding rate
func (*Depth) IsRestSnapshot ¶
IsRestSnapshot returns if the depth item was updated via REST
func (*Depth) LastUpdateID ¶
LastUpdateID returns the last Update ID
func (*Depth) LoadSnapshot ¶
func (d *Depth) LoadSnapshot(bids, asks []Item, lastUpdateID int64, lastUpdated time.Time, updateByREST bool)
LoadSnapshot flushes the bids and asks with a snapshot
func (*Depth) Publish ¶
func (d *Depth) Publish()
Publish alerts any subscribed routines using a dispatch mux
func (*Depth) Retrieve ¶
Retrieve returns the orderbook base a copy of the underlying linked list spread
func (*Depth) TotalAskAmounts ¶
TotalAskAmounts returns the total amount of asks and the total orderbook asks value
func (*Depth) TotalBidAmounts ¶
TotalBidAmounts returns the total amount of bids and the total orderbook bids value
func (*Depth) UpdateBidAskByID ¶
func (d *Depth) UpdateBidAskByID(bidUpdts, askUpdts Items, lastUpdateID int64, lastUpdated time.Time) error
UpdateBidAskByID amends details by ID
func (*Depth) UpdateBidAskByPrice ¶
func (d *Depth) UpdateBidAskByPrice(bidUpdts, askUpdts Items, maxDepth int, lastUpdateID int64, lastUpdated time.Time)
UpdateBidAskByPrice updates the bid and ask spread by supplied updates, this will trim total length of depth level to a specified supplied number
type Exchange ¶
Exchange defines a holder for the exchange specific depth items with a specific ID associated with that exchange
type Item ¶
type Item struct { Amount float64 Price float64 ID int64 // Funding rate field Period int64 // Contract variables LiquidationOrders int64 OrderCount int64 }
Item stores the amount and price values
type Items ¶
type Items []Item
Items defines a slice of orderbook items
func (Items) FindNominalAmount ¶
FindNominalAmount finds the nominal amount spent in terms of the quote If the orderbook doesn't have enough liquidity it returns a non zero remaining amount value
func (*Items) Reverse ¶
func (elem *Items) Reverse()
Reverse reverses the order of orderbook items; some bid/asks are returned in either ascending or descending order. One bid or ask slice depending on whats received can be reversed. This is usually faster than using a sort algorithm as the algorithm could be impeded by a worst case time complexity when elements are shifted as opposed to just swapping element values.
type OrderSimulationResult ¶
type OrderSimulationResult WhaleBombResult
OrderSimulationResult returns the order simulation result
type Service ¶
Service provides a store for difference exchange orderbooks
func (*Service) DeployDepth ¶
DeployDepth used for subsystem deployment creates a depth item in the struct then returns a ptr to that Depth item
func (*Service) GetDepth ¶
GetDepth returns the actual depth struct for potential subsystems and strategies to interact with
type Unsafe ¶
type Unsafe struct { BidHead **Node AskHead **Node // UpdatedViaREST defines if sync manager is updating this book via the REST // protocol then this book is not considered live and cannot be trusted. UpdatedViaREST *bool LastUpdated *time.Time *alert.Notice // contains filtered or unexported fields }
Unsafe is an exported linked list reference to the current bid/ask heads and a reference to the underlying depth mutex. This allows for the exposure of the internal list to an external strategy or subsystem. The bid and ask fields point to the actual head fields contained on both linked list structs, so that this struct can be reusable and not needed to be called on each inspection.
func (*Unsafe) Lock ¶
func (src *Unsafe) Lock()
Lock locks down the underlying linked list which inhibits all pending updates for strategy inspection.
func (*Unsafe) LockWith ¶
LockWith locks both books for the context of cross orderbook inspection. WARNING: When inspecting diametrically opposed books a higher order mutex MUST be used or a dead lock will occur.
func (*Unsafe) Unlock ¶
func (src *Unsafe) Unlock()
Unlock unlocks the underlying linked list after inspection by a strategy to resume normal operations
func (*Unsafe) UnlockWith ¶
UnlockWith unlocks both books for the context of cross orderbook inspection