Documentation
¶
Overview ¶
Package book is a limit order book for one instrument: price-time priority, partial fills, and cancels.
An incoming order first trades against the opposite side, best price first and, within a price, oldest first. Each trade happens at the RESTING order's price. Whatever is left over rests on its own side at its own limit price, behind every order already resting at that price.
Prices are integers in ticks (the exchange uses hundredths), so no float ever decides which order is better. A Book is not safe for concurrent use; the exchange holds one lock around every call.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadSide = errors.New("side must be buy or sell") ErrBadPrice = errors.New("price must be positive") ErrBadQty = errors.New("quantity must be positive") ErrDupID = errors.New("an order with this ID is already in the book") )
Errors an order can be refused with before it touches the book.
Functions ¶
This section is empty.
Types ¶
type Book ¶
type Book struct {
Symbol string
// contains filtered or unexported fields
}
Book is one instrument's bids and asks.
func (*Book) Cancel ¶
Cancel removes the resting order with this ID and returns it as it was (Leaves is what was still open). ok is false when no such order rests, including one that has already filled.
func (*Book) OwnerOrders ¶
OwnerOrders returns copies of every order owner has resting, oldest first.
type Fill ¶
Fill is one trade between the incoming order and one resting order. Both orders are copies taken just after the trade, so their Leaves are what is open after it.
type Order ¶
type Order struct {
ID string
Owner string
ClOrdID string
Side Side
Price int64
Qty int64
Leaves int64
// Seq is the book's arrival counter, which is what "time" means in
// price-time priority: a lower Seq at the same price trades first.
Seq uint64
}
Order is one limit order. Qty is what was asked for and Leaves what is still open; Qty-Leaves has traded.