Documentation ¶
Overview ¶
Package orderbook is a Limit Order Book for high-frequency trading.
Index ¶
- Variables
- type Depth
- type Order
- type OrderBook
- func (ob *OrderBook) CancelOrder(orderID string) *Order
- func (ob *OrderBook) Depth() *Depth
- func (ob *OrderBook) MarshalJSON() ([]byte, error)
- func (ob *OrderBook) ProcessLimitOrder(orderID, traderID string, side Side, amount, price decimal.Decimal) ([]*Trade, error)
- func (ob *OrderBook) ProcessMarketOrder(orderID, traderID string, side Side, amount, price decimal.Decimal) ([]*Trade, error)
- func (ob *OrderBook) ProcessPostOnlyOrder(orderID, traderID string, side Side, amount, price decimal.Decimal) ([]*Trade, error)
- func (ob *OrderBook) Quote(traderID string, side Side, amount decimal.Decimal) (*Quote, error)
- func (ob *OrderBook) Reset(version uint64)
- func (ob *OrderBook) Symbol() string
- func (ob *OrderBook) UnmarshalJSON(data []byte) error
- func (ob *OrderBook) Version() uint64
- type OrderQueue
- func (oq *OrderQueue) Amount() decimal.Decimal
- func (oq *OrderQueue) Append(order *Order) *list.Element
- func (oq *OrderQueue) Back() *list.Element
- func (oq *OrderQueue) Front() *list.Element
- func (oq *OrderQueue) Len() int
- func (oq *OrderQueue) Orders() *list.List
- func (oq *OrderQueue) Price() decimal.Decimal
- func (oq *OrderQueue) Remove(e *list.Element) *Order
- func (oq *OrderQueue) UpdateAmount(e *list.Element, amount decimal.Decimal) *Order
- type OrderSide
- func (os *OrderSide) Append(order *Order) *list.Element
- func (os *OrderSide) GreaterThan(price decimal.Decimal) *OrderQueue
- func (os *OrderSide) LessThan(price decimal.Decimal) *OrderQueue
- func (os *OrderSide) MaxPriceQueue() *OrderQueue
- func (os *OrderSide) MinPriceQueue() *OrderQueue
- func (os *OrderSide) Orders() []*Order
- func (os *OrderSide) Remove(e *list.Element) *Order
- func (os *OrderSide) UpdateAmount(e *list.Element, amount decimal.Decimal) *Order
- type PriceLevel
- type Quote
- type Side
- type Trade
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidOrderID = errors.New("Invalid order id") ErrInvalidTraderID = errors.New("Invalid trader id") ErrInvalidAmount = errors.New("Invalid amount") ErrInvalidPrice = errors.New("Invalid price") ErrInvalidSide = errors.New("Invalid side") ErrOrderAlreadyExists = errors.New("Order already exists") )
Orderbook erros
Functions ¶
This section is empty.
Types ¶
type Depth ¶
type Depth struct {
// contains filtered or unexported fields
}
Depth represents a order book depth.
func (*Depth) MarshalJSON ¶
MarshalJSON implements json.MarshalJSON.
func (*Depth) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Order ¶
type Order struct {
// contains filtered or unexported fields
}
Order represents a bid or an ask.
func (*Order) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Order) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type OrderBook ¶
OrderBook represents a order book for a given market symbol.
func NewOrderBook ¶
NewOrderBook creates a new order book.
func Restore ¶
Restore restores a new order book from raw representation. Raw format is a nested arrays like: raw[ask[price][amount]][bid[price][amount]][symbol].
func (*OrderBook) CancelOrder ¶
CancelOrder canacels an order.
func (*OrderBook) MarshalJSON ¶
MarshalJSON implements json.MarshalJSON.
func (*OrderBook) ProcessLimitOrder ¶
func (ob *OrderBook) ProcessLimitOrder(orderID, traderID string, side Side, amount, price decimal.Decimal) ([]*Trade, error)
ProcessLimitOrder processes a limit order.
func (*OrderBook) ProcessMarketOrder ¶
func (ob *OrderBook) ProcessMarketOrder(orderID, traderID string, side Side, amount, price decimal.Decimal) ([]*Trade, error)
ProcessMarketOrder processes a market order.
func (*OrderBook) ProcessPostOnlyOrder ¶
func (ob *OrderBook) ProcessPostOnlyOrder(orderID, traderID string, side Side, amount, price decimal.Decimal) ([]*Trade, error)
ProcessPostOnlyOrder processes a post only order.
func (*OrderBook) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type OrderQueue ¶
type OrderQueue struct {
// contains filtered or unexported fields
}
OrderQueue represents a queue of orders.
func NewOrderQueue ¶
func NewOrderQueue(price decimal.Decimal) *OrderQueue
NewOrderQueue creates a new order queue.
func (*OrderQueue) Amount ¶
func (oq *OrderQueue) Amount() decimal.Decimal
Amount returns the queue amout.
func (*OrderQueue) Append ¶
func (oq *OrderQueue) Append(order *Order) *list.Element
Append appends an order.
func (*OrderQueue) Back ¶
func (oq *OrderQueue) Back() *list.Element
Back returns the last order of the queue.
func (*OrderQueue) Front ¶
func (oq *OrderQueue) Front() *list.Element
Front returns the first order of the queue.
func (*OrderQueue) Orders ¶
func (oq *OrderQueue) Orders() *list.List
Orders returns the orders as a list.
func (*OrderQueue) Price ¶
func (oq *OrderQueue) Price() decimal.Decimal
Price returns the queue price.
func (*OrderQueue) Remove ¶
func (oq *OrderQueue) Remove(e *list.Element) *Order
Remove removes an order.
func (*OrderQueue) UpdateAmount ¶
UpdateAmount updates an order amount.
type OrderSide ¶
type OrderSide struct {
// contains filtered or unexported fields
}
OrderSide represents all the prices about bids or asks.
func (*OrderSide) GreaterThan ¶
func (os *OrderSide) GreaterThan(price decimal.Decimal) *OrderQueue
GreaterThan returns the order queue for the price greater than the given price.
func (*OrderSide) LessThan ¶
func (os *OrderSide) LessThan(price decimal.Decimal) *OrderQueue
LessThan returns the order queue for the price less than the given price.
func (*OrderSide) MaxPriceQueue ¶
func (os *OrderSide) MaxPriceQueue() *OrderQueue
MaxPriceQueue returns the order queue for the max price.
func (*OrderSide) MinPriceQueue ¶
func (os *OrderSide) MinPriceQueue() *OrderQueue
MinPriceQueue returns the order queue for the min price.
func (*OrderSide) Orders ¶
Orders return all the orders sorted by price. Desc when side is buy. Asc when side is sell.
type PriceLevel ¶
type PriceLevel struct {
// contains filtered or unexported fields
}
PriceLevel takes a count of how many assets have that price.
func NewPriceLevel ¶
func NewPriceLevel(price, amount decimal.Decimal) *PriceLevel
NewPriceLevel creates a new price level.
func (*PriceLevel) Amount ¶
func (p *PriceLevel) Amount() decimal.Decimal
Amount returns the amount.
func (*PriceLevel) MarshalJSON ¶
func (p *PriceLevel) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler.
func (*PriceLevel) UnmarshalJSON ¶
func (p *PriceLevel) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler.
type Quote ¶
type Quote struct {
// contains filtered or unexported fields
}
Quote represents a quote.
func (*Quote) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Quote) RemainingAmount ¶
RemainingAmount returns the remaining amount.
func (*Quote) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Side ¶
type Side int
A Side of the order.
func (Side) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Side) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.
type Trade ¶
type Trade struct {
// contains filtered or unexported fields
}
Trade represents a match between a maker order and a taker order.
func (*Trade) MakerOrderID ¶
MakerOrderID returns the maker order id.
func (*Trade) MarshalJSON ¶
MarshalJSON implements json.Marshaler.
func (*Trade) TakerOrderID ¶
TakerOrderID returns the taker order id.
func (*Trade) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler.