Documentation ¶
Index ¶
- func NaturalPriceComparator(a, b interface{}) int
- func OppositePriceComparator(a, b interface{}) int
- type Instrument
- type OrderBook
- func (o *OrderBook) Add(side Side, price Price, quantity Volume)
- func (o *OrderBook) GetAskSize(price Price) Volume
- func (o *OrderBook) GetBestAsk() (Price, Volume)
- func (o *OrderBook) GetBestBid() (Price, Volume)
- func (o *OrderBook) GetBidSize(price Price) Volume
- func (o *OrderBook) Update(side Side, price Price, quantity Volume)
- type Price
- type Side
- type Volume
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NaturalPriceComparator ¶
func NaturalPriceComparator(a, b interface{}) int
NaturalPriceComparator provides a way to compare 2 Price objects using natural order.
func OppositePriceComparator ¶
func OppositePriceComparator(a, b interface{}) int
OppositePriceComparator provides a way to compare 2 Price objects using opposite natural order.
Types ¶
type Instrument ¶
type Instrument string
Instrument describes which markets exists.
var ( BTC_USD Instrument = "btc-usd" BTC_ETH Instrument = "btc-eth" )
type OrderBook ¶
type OrderBook struct {
// contains filtered or unexported fields
}
OrderBook represents both bids (BUY) and asks (SELL). For each one it will hold a height balanced binary search tree. The order book is a tree in which the price are keys and the values are volumes.
func NewOrderBook ¶
func NewOrderBook(instrument Instrument) *OrderBook
func (*OrderBook) Add ¶
Add adds a BUY or SELL order into the order orderbook according to its price. If the order already exists it will increase the order quantity.
func (*OrderBook) GetAskSize ¶
GetAskSize returns the ask (SELL) volume size otherwise 0
func (*OrderBook) GetBestAsk ¶
GetBestAsk returns the best (highest) ask and its volume
func (*OrderBook) GetBestBid ¶
GetBestBid returns the best (highest) bid and its volume
func (*OrderBook) GetBidSize ¶
GetBidSize returns the bid (BUY) volume size otherwise 0
type Price ¶
type Price uint64
Price describes the price of a market order. To facilitate usage we avoid using float. Instead we must store prices as unsigned integers by multiplying it by 100000000.
Example: 1.00000061 should be stored as 100000061