Documentation
¶
Overview ¶
GoOrderBook builds on the google btree library to provide the ability to maintain real time orderbooks not limited to, cyrpto, assets, currencies and lending books.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Order ¶
type Order struct {
// Id is the id of the order on this book level
Id string
// Amount is the amount that this order is willing to buy/sell
Amount uint64
// Timesetamp is the time that this order was placed on the book in
// nanoseconds.
Timestamp uint64
}
Order represents an order on a book level
type OrderBook ¶
type OrderBook interface {
// PutBid calls Put on the bid side
PutBid(order Order, level uint64)
// PutAsk calls Put on the ask side
PutAsk(order Order, level uint64)
// GetBid calls Get on the bid side
GetBid(level uint64) OrderBookLevel
// GetAsk calls Get on the ask side
GetAsk(level uint64) OrderBookLevel
// RemoveBid calls Remove of the bid side
RemoveBid(orderId string) error
// RemoveAsk calls Remove on the ask side
RemoveAsk(orderId string) error
// ModifyBid modifies an order the bid side
ModifyBid(order Order, level uint64) error
// ModifyAsk modifies an order on the ask side
ModifyAsk(order Order, level uint64) error
// TopBid returns the top of the bid book
TopBid() OrderBookLevel
// TopAsk returns the top of the ask book
TopAsk() OrderBookLevel
// Sequence returns the sequence number of the last message
GetSequence() uint64
// SetSequence sets the sequence number for this orderbook
SetSequence(sequence uint64)
}
OrderBook builds upon the OrderBookSide int64erface. Orderbook simply holds two order book sides, one for the bid side and one for the ask side. The functions PutBid/PutAsk/Get*** etc... are pass through functions to the correct order book side.
type OrderBookLevel ¶
type OrderBookLevel struct {
// The orders in this level
Orders []Order
// Level is the bid or ask price that lies on the book
Level uint64
}
OrderBookLevel contains a list of orders that make up the entire level
func (OrderBookLevel) IsNil ¶
func (r OrderBookLevel) IsNil() bool
IsNil returns true if the order book level contains no information.
func (OrderBookLevel) Less ¶
func (r OrderBookLevel) Less(b btree.Item) bool
Less implements the btree.Item interface for our OrderBookLevel. Returns true if LevelA is less than LevelB
func (OrderBookLevel) Total ¶
func (r OrderBookLevel) Total() uint64
Total gets the total number amount of an orderbook level
type OrderBookSide ¶
type OrderBookSide interface {
// Puts a level on the order book
Put(order Order, level uint64)
// Gets a level from the order book
Get(level uint64) OrderBookLevel
// Removes an order from the order book
Remove(orderId string) error
// Modifies an order already on the book, throws an error if the order
// can not be found
Modify(order Order, level uint64) error
// Max returns the maximum value in the orderbook or a nil orderbooklevel.
// The nil orderbook level is only returned if there are no elements in
// the book.
Max() OrderBookLevel
// Min returns the minimum value in the orderbook or a nil orderbooklevel.
// The nil orderbook level is only returned if there are no elements in
// the book.
Min() OrderBookLevel
}
OrderBookSide represents either the bid or ask side of the order book