Documentation ¶
Overview ¶
Package redblacktree implements a red-black tree.
Used by TreeSet and TreeMap.
Structure is not thread safe.
References: http://en.wikipedia.org/wiki/Red%E2%80%93black_tree
Package redblacktree implements a red-black tree.
Used by TreeSet and TreeMap.
Structure is not thread safe.
References: http://en.wikipedia.org/wiki/Red%E2%80%93black_tree
Index ¶
Constants ¶
const ( None FlagType = 0 IoC = 1 AoN = 2 FoK = 4 StopLoss = 8 TakeProfit = 16 Snapshot = 32 )
Market or Limit
Variables ¶
var ( ErrInvalidQuantity = errors.New("orderbook: invalid order quantity") ErrInvalidPrice = errors.New("orderbook: invalid order price") ErrInvalidTriggerPrice = errors.New("orderbook: invalid trigger price") ErrOrderID = errors.New("orderbook: order id is less than previous order ids") ErrOrderExists = errors.New("orderbook: order already exists") ErrOrderNotExists = errors.New("orderbook: order does not exist") ErrInsufficientQuantity = errors.New("orderbook: insufficient quantity to calculate price") ErrNoMatching = errors.New("orderbook: matching disabled") )
OrderBook erros
Functions ¶
Types ¶
type NotificationHandler ¶
type NotificationHandler interface { PutOrder(m MsgType, s OrderStatus, orderID uint64, qty decimal.Decimal, err error) PutTrade(makerOrderID, takerOrderID uint64, makerStatus, takerStatus OrderStatus, qty, price decimal.Decimal) }
NotificationHandler handles notification updates
type Option ¶
type Option func(*OrderBook)
func WithNodeTreePoolSize ¶
WithNodeTreePoolSize sets the size of the node tree pool
func WithOrderPoolSize ¶
WithOrderPoolSize sets the size of the order pool
func WithOrderQueuePoolSize ¶
WithOrderQueuePoolSize sets the size of the order queue pool
func WithOrderTreeNodePoolSIze ¶
WithOrderTreeNodePoolSize sets the size of the order tree node pool
type Order ¶
type Order struct { ID uint64 `json:"id" ` Class ClassType `json:"class" ` Side SideType `json:"side" ` Flag FlagType `json:"flag" ` Qty decimal.Decimal `json:"qty" ` Price decimal.Decimal `json:"price" ` TrigPrice decimal.Decimal `json:"trigPrice" ` // contains filtered or unexported fields }
Order strores information about request
func NewOrder ¶
func NewOrder(orderID uint64, class ClassType, side SideType, qty, price, trigPrice decimal.Decimal, flag FlagType) *Order
NewOrder creates new constant object Order
type OrderBook ¶
type OrderBook struct {
// contains filtered or unexported fields
}
OrderBook implements standard matching algorithm
func NewOrderBook ¶
func NewOrderBook(n NotificationHandler, opts ...Option) *OrderBook
NewOrderBook creates Orderbook object
func (*OrderBook) AddOrder ¶
func (ob *OrderBook) AddOrder(tok, id uint64, class ClassType, side SideType, quantity, price, trigPrice decimal.Decimal, flag FlagType)
AddOrder places new order to the OrderBook Arguments:
orderID - unique order ID in depth (uint64) class - what class of order do you want to place (ob.Market or ob.Limit) side - what do you want to do (ob.Sell or ob.Buy) quantity - how much quantity you want to sell or buy (decimal) price - no more expensive (or cheaper) this price (decimal) trigPrice - create a stop/take order until market price reaches this price (decimal) flag - immediate or cancel, all or none, fill or kill, Cancel (ob.IoC or ob.AoN or ob.FoK or ob.Cancel) * to create new decimal number you should use udecimal.New() func read more at https://github.com/geseq/udecimal
func (*OrderBook) CancelOrder ¶
CancelOrder removes order with given ID from the order book
type OrderStatus ¶
type OrderStatus byte
OrderStatus of the order
const ( Rejected OrderStatus = iota Canceled FilledPartial FilledComplete Accepted )
func (OrderStatus) String ¶
func (o OrderStatus) String() string
String implements Stringer interface
type Trade ¶
type Trade struct { MakerOrderID uint64 `json:"makerOrderId" ` TakerOrderID uint64 `json:"takerOrderId" ` MakerStatus OrderStatus `json:"makerStatus" ` TakerStatus OrderStatus `json:"takerStatus" ` Qty decimal.Decimal `json:"qty"` Price decimal.Decimal `json:"price" ` }
Trade strores information about request