Documentation ¶
Index ¶
- type Broker
- func (m *Broker) Add(order *Order) *LinkedListElement
- func (m *Broker) GreaterThan(price Decimal) *OrderQueue
- func (m *Broker) LessThan(price Decimal) *OrderQueue
- func (m *Broker) MaxPriceQueue() *OrderQueue
- func (m *Broker) MinPriceQueue() *OrderQueue
- func (m *Broker) Remove(e *LinkedListElement) *Order
- type Decimal
- type Kind
- type LinkedList
- type LinkedListElement
- type Market
- func (m *Market) CancelOrder(orderID string) *Order
- func (m *Market) Depth() ([]PriceVolume, []PriceVolume)
- func (m *Market) MakeBuyPrice(volume Decimal) (Decimal, error)
- func (m *Market) MakeSellPrice(volume Decimal) (Decimal, error)
- func (m *Market) Order(orderID string) *Order
- func (m *Market) ProcessBuy(volume Decimal) ([]*Order, *Order, Decimal, Decimal, error)
- func (m *Market) ProcessBuyOrder(orderID string, volume, price Decimal) ([]*Order, *Order, Decimal, error)
- func (m *Market) ProcessSell(volume Decimal) ([]*Order, *Order, Decimal, Decimal, error)
- func (m *Market) ProcessSellOrder(orderID string, volume, price Decimal) ([]*Order, *Order, Decimal, error)
- type Order
- type OrderQueue
- func (q *OrderQueue) Add(order *Order) *LinkedListElement
- func (q *OrderQueue) Head() *LinkedListElement
- func (q *OrderQueue) Len() int
- func (q *OrderQueue) Remove(e *LinkedListElement) *Order
- func (q *OrderQueue) Tail() *LinkedListElement
- func (q *OrderQueue) Update(element *LinkedListElement, order *Order) *LinkedListElement
- type PriceVolume
- type Processed
- type RedBlackTree
- type TreeNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
func (*Broker) Add ¶
func (m *Broker) Add(order *Order) *LinkedListElement
Add appends order to definite price level
func (*Broker) GreaterThan ¶
func (m *Broker) GreaterThan(price Decimal) *OrderQueue
GreaterThan returns the nearest OrderQueue with price greater than given
func (*Broker) LessThan ¶
func (m *Broker) LessThan(price Decimal) *OrderQueue
LessThan returns the nearest OrderQueue with price less than given
func (*Broker) MaxPriceQueue ¶
func (m *Broker) MaxPriceQueue() *OrderQueue
MaxPriceQueue returns maximal level of price
func (*Broker) MinPriceQueue ¶
func (m *Broker) MinPriceQueue() *OrderQueue
MinPriceQueue returns maximal level of price
func (*Broker) Remove ¶
func (m *Broker) Remove(e *LinkedListElement) *Order
Remove removes order from definite price level
type LinkedList ¶
type LinkedList struct { Len int // current list length excluding (this) sentinel element // contains filtered or unexported fields }
LinkedList represents a doubly linked list. The zero value for LinkedList is an empty list ready to use.
func (*LinkedList) Append ¶
func (l *LinkedList) Append(v *Order) *LinkedListElement
Append inserts a new element e with value v at the back of list l and returns e.
func (*LinkedList) Back ¶
func (l *LinkedList) Back() *LinkedListElement
Back returns the last element of list l or nil if the list is empty.
func (*LinkedList) Front ¶
func (l *LinkedList) Front() *LinkedListElement
Front returns the first element of list l or nil if the list is empty.
func (*LinkedList) Init ¶
func (l *LinkedList) Init() *LinkedList
Init initializes or clears list l.
func (*LinkedList) Remove ¶
func (l *LinkedList) Remove(e *LinkedListElement) any
Remove removes e from l if e is an element of list l. It returns the element value e.OrderQueue. The element must not be nil.
type LinkedListElement ¶
type LinkedListElement struct { Order *Order // contains filtered or unexported fields }
func (*LinkedListElement) Next ¶
func (e *LinkedListElement) Next() *LinkedListElement
Next returns the next list element or nil.
func (*LinkedListElement) Prev ¶
func (e *LinkedListElement) Prev() *LinkedListElement
Prev returns the previous list element or nil.
type Market ¶
type Market struct {
// contains filtered or unexported fields
}
func (*Market) CancelOrder ¶
func (*Market) Depth ¶
func (m *Market) Depth() ([]PriceVolume, []PriceVolume)
Depth returns price levels and volumes at price level
func (*Market) MakeBuyPrice ¶
MakeBuyPrice returns total market buy price for requested volume
func (*Market) MakeSellPrice ¶
MakeSellPrice returns total market sell price for requested volume
func (*Market) ProcessBuy ¶
ProcessBuy - buys for a volume
func (*Market) ProcessBuyOrder ¶
func (m *Market) ProcessBuyOrder(orderID string, volume, price Decimal) ([]*Order, *Order, Decimal, error)
ProcessBuyOrder places new buy order to the Market
orderID - unique order ID volume - how much volume you want to buy price - no more expensive this price
Result :
A slice of 'done' orders - if your order satisfies another order, these orders will be added to this slice. If your own order is 'done' too, it will be placed into this slice as well partial - if your order has been 'done' but the top order is not fully done, or if your order is 'partial done' and placed to the market without full volume - partial will contain your order with volume left partialVolume - if partial order is not nil this result contains processed volume from partial order error - not nil if volume (or price) is less or equal 0. Or if order with given ID is exists
func (*Market) ProcessSell ¶
ProcessSell - sells a volume
func (*Market) ProcessSellOrder ¶
func (m *Market) ProcessSellOrder(orderID string, volume, price Decimal) ([]*Order, *Order, Decimal, error)
ProcessSellOrder places new sell order to the Market
orderID - unique order ID volume - how much volume you want to sell price - no less cheap than this price
Result :
A slice of 'done' orders - if your order satisfies another order, these orders will be added to this slice. If your own order is 'done' too, it will be placed into this slice as well partial - if your order has been 'done' but the top order is not fully done, or if your order is 'partial done' and placed to the market without full volume - partial will contain your order with volume left partialVolume - if partial order is not nil this result contains processed volume from partial order error - not nil if volume (or price) is less or equal 0. Or if order with given ID is exists
type OrderQueue ¶
OrderQueue stores and manage chain of orders
func NewQueue ¶
func NewQueue(price Decimal) *OrderQueue
NewQueue creates and initialize OrderQueue object
func (*OrderQueue) Add ¶
func (q *OrderQueue) Add(order *Order) *LinkedListElement
Add adds order to tail of the queue
func (*OrderQueue) Head ¶
func (q *OrderQueue) Head() *LinkedListElement
Head returns top order in queue
func (*OrderQueue) Remove ¶
func (q *OrderQueue) Remove(e *LinkedListElement) *Order
Remove removes order from the queue and link order chain
func (*OrderQueue) Tail ¶
func (q *OrderQueue) Tail() *LinkedListElement
Tail returns bottom order in queue
func (*OrderQueue) Update ¶
func (q *OrderQueue) Update(element *LinkedListElement, order *Order) *LinkedListElement
Update sets up new order to list value
type PriceVolume ¶
type RedBlackTree ¶
type RedBlackTree struct { Root *TreeNode // contains filtered or unexported fields }
RedBlackTree holds elements of the red-black tree
func (*RedBlackTree) Empty ¶
func (t *RedBlackTree) Empty() bool
Empty returns true if tree does not contain any nodes
func (*RedBlackTree) Max ¶
func (t *RedBlackTree) Max() (*OrderQueue, bool)
Max gets the max value and flag if found
func (*RedBlackTree) Min ¶
func (t *RedBlackTree) Min() (*OrderQueue, bool)
Min gets the min value and flag if found
func (*RedBlackTree) Put ¶
func (t *RedBlackTree) Put(price Decimal, queue *OrderQueue)
Put inserts node into the tree.
func (*RedBlackTree) Remove ¶
func (t *RedBlackTree) Remove(price Decimal)
Remove the node from the tree.
type TreeNode ¶
type TreeNode struct { Queue *OrderQueue Left *TreeNode Right *TreeNode Price Decimal // contains filtered or unexported fields }
TreeNode is a single leaf of the tree