orderbook

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const MaxLimitsNum int = 10000

MaxLimitsNum maximum limits per order book side to pre-allocate memory

Variables

This section is empty.

Functions

This section is empty.

Types

type IndexMinPQ

type IndexMinPQ struct {
	// contains filtered or unexported fields
}

IndexMinPQ Indexed minimum oriented Priority Queue

func NewIndexMinPQ

func NewIndexMinPQ(size int) IndexMinPQ

func (*IndexMinPQ) Change

func (pq *IndexMinPQ) Change(i int, key float64)

func (*IndexMinPQ) Contains

func (pq *IndexMinPQ) Contains(i int) bool

func (*IndexMinPQ) DelTop

func (pq *IndexMinPQ) DelTop() int

DelTop removes minimal element and returns its index

func (*IndexMinPQ) Delete

func (pq *IndexMinPQ) Delete(i int)

func (*IndexMinPQ) Insert

func (pq *IndexMinPQ) Insert(i int, key float64)

func (*IndexMinPQ) IsEmpty

func (pq *IndexMinPQ) IsEmpty() bool

func (*IndexMinPQ) Size

func (pq *IndexMinPQ) Size() int

func (*IndexMinPQ) Top

func (pq *IndexMinPQ) Top() float64

func (*IndexMinPQ) TopIndex

func (pq *IndexMinPQ) TopIndex() int

type LimitOrder

type LimitOrder struct {
	Price float64
	// contains filtered or unexported fields
}

LimitOrder price orders combined as a FIFO queue

func NewLimitOrder

func NewLimitOrder(price float64) LimitOrder

func (*LimitOrder) Clear

func (lo *LimitOrder) Clear()

func (*LimitOrder) Delete

func (lo *LimitOrder) Delete(o *Order)

func (*LimitOrder) Dequeue

func (lo *LimitOrder) Dequeue() *Order

func (*LimitOrder) Enqueue

func (lo *LimitOrder) Enqueue(o *Order)

func (*LimitOrder) Size

func (lo *LimitOrder) Size() int

func (*LimitOrder) TotalVolume

func (lo *LimitOrder) TotalVolume() float64

type MinPQ

type MinPQ struct {
	// contains filtered or unexported fields
}

MinPQ Minimum Oriented Priority Queue

func NewMinPQ

func NewMinPQ(size int) MinPQ

func (*MinPQ) DelTop

func (pq *MinPQ) DelTop() float64

DelTop removes minimal element and returns it

func (*MinPQ) Insert

func (pq *MinPQ) Insert(key float64)

func (*MinPQ) IsEmpty

func (pq *MinPQ) IsEmpty() bool

func (*MinPQ) Size

func (pq *MinPQ) Size() int

func (*MinPQ) Top

func (pq *MinPQ) Top() float64

type Node

type Node struct {
	Key   float64
	Value *LimitOrder
	Next  *Node
	Prev  *Node
	// contains filtered or unexported fields
}

type Order

type Order struct {
	Id       int
	Volume   float64
	Next     *Order
	Prev     *Order
	Limit    *LimitOrder
	BidOrAsk bool
}

Order defines a single order in the orderbook, as a node in a LimitOrder FIFO queue

type Orderbook

type Orderbook struct {
	Bids *Tree
	Asks *Tree
	// contains filtered or unexported fields
}

func NewOrderbook

func NewOrderbook() *Orderbook

func (*Orderbook) ALength

func (book *Orderbook) ALength() int

func (*Orderbook) Add

func (book *Orderbook) Add(price float64, o *Order)

func (*Orderbook) BLength

func (book *Orderbook) BLength() int

func (*Orderbook) Cancel

func (book *Orderbook) Cancel(o *Order)

func (*Orderbook) ClearAskLimit

func (book *Orderbook) ClearAskLimit(price float64)

func (*Orderbook) ClearBidLimit

func (book *Orderbook) ClearBidLimit(price float64)

func (*Orderbook) DeleteAskLimit

func (book *Orderbook) DeleteAskLimit(price float64)

func (*Orderbook) DeleteBidLimit

func (book *Orderbook) DeleteBidLimit(price float64)

func (*Orderbook) GetBestBid

func (book *Orderbook) GetBestBid() float64

func (*Orderbook) GetBestOffer

func (book *Orderbook) GetBestOffer() float64

func (*Orderbook) GetVolumeAtAskLimit

func (book *Orderbook) GetVolumeAtAskLimit(price float64) float64

func (*Orderbook) GetVolumeAtBidLimit

func (book *Orderbook) GetVolumeAtBidLimit(price float64) float64

func (*Orderbook) NewOrder

func (book *Orderbook) NewOrder() *Order

type OrdersQueue

type OrdersQueue struct {
	// contains filtered or unexported fields
}

OrdersQueue Doubly linked orders queue TODO: this should be compared with ring buffer queue performance

func NewOrdersQueue

func NewOrdersQueue() OrdersQueue

func (*OrdersQueue) Delete

func (q *OrdersQueue) Delete(o *Order)

func (*OrdersQueue) Dequeue

func (q *OrdersQueue) Dequeue() *Order

func (*OrdersQueue) Enqueue

func (q *OrdersQueue) Enqueue(o *Order)

func (*OrdersQueue) IsEmpty

func (q *OrdersQueue) IsEmpty() bool

func (*OrdersQueue) Size

func (q *OrdersQueue) Size() int

type Tree

type Tree struct {
	// contains filtered or unexported fields
}

func NewTree

func NewTree() Tree

func (*Tree) Ceiling

func (t *Tree) Ceiling(key float64) float64

func (*Tree) Contains

func (t *Tree) Contains(key float64) bool

func (*Tree) Delete

func (t *Tree) Delete(key float64)

func (*Tree) DeleteMax

func (t *Tree) DeleteMax()

func (*Tree) DeleteMin

func (t *Tree) DeleteMin()

func (*Tree) Floor

func (t *Tree) Floor(key float64) float64

func (*Tree) Get

func (t *Tree) Get(key float64) *LimitOrder

func (*Tree) Height

func (t *Tree) Height() int

func (*Tree) IsEmpty

func (t *Tree) IsEmpty() bool

func (*Tree) IsRedBlack

func (t *Tree) IsRedBlack() bool

func (*Tree) Keys

func (t *Tree) Keys(lo, hi float64) []float64

func (*Tree) Max

func (t *Tree) Max() float64

func (*Tree) MaxPointer

func (t *Tree) MaxPointer() *Node

func (*Tree) MaxValue

func (t *Tree) MaxValue() *LimitOrder

func (*Tree) Min

func (t *Tree) Min() float64

func (*Tree) MinPointer

func (t *Tree) MinPointer() *Node

func (*Tree) MinValue

func (t *Tree) MinValue() *LimitOrder

func (*Tree) Print

func (t *Tree) Print()

func (*Tree) Put

func (t *Tree) Put(key float64, value *LimitOrder)

func (*Tree) Rank

func (t *Tree) Rank(key float64) int

func (*Tree) Select

func (t *Tree) Select(k int) float64

func (*Tree) Size

func (t *Tree) Size() int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL