orderbook

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: BlueOak-1.0.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const ErrEmptyOrderbook = dex.ErrorKind("cannot calculate mid-gap from empty order book")

ErrEmptyOrderbook is returned from MidGap when the order book is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EpochQueue

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

EpochQueue represents a client epoch queue.

func NewEpochQueue

func NewEpochQueue() *EpochQueue

NewEpochQueue creates a client epoch queue.

func (*EpochQueue) Enqueue

func (eq *EpochQueue) Enqueue(note *msgjson.EpochOrderNote) error

Enqueue appends the provided order note to the epoch queue.

func (*EpochQueue) Exists

func (eq *EpochQueue) Exists(oid order.OrderID) bool

Exists checks if the provided order id is in the queue.

func (*EpochQueue) GenerateMatchProof

func (eq *EpochQueue) GenerateMatchProof(preimages []order.Preimage, misses []order.OrderID) (msgjson.Bytes, msgjson.Bytes, error)

GenerateMatchProof calculates the sorting seed used in order matching as well as the commitment checksum from the provided epoch queue preimages and misses.

The epoch queue needs to be reset if there are preimage mismatches or non-existent orders for preimage errors.

func (*EpochQueue) Orders

func (eq *EpochQueue) Orders() (orders []*Order)

Orders returns the epoch queue as a []*Order.

func (*EpochQueue) Size

func (eq *EpochQueue) Size() int

Size returns the number of entries in the epoch queue.

type Fill added in v0.2.0

type Fill struct {
	Rate     uint64
	Quantity uint64
}

Fill represents an order fill.

type MatchSummary added in v0.6.0

type MatchSummary struct {
	Rate  uint64 `json:"rate"`
	Qty   uint64 `json:"qty"`
	Stamp uint64 `json:"stamp"`
	Sell  bool   `json:"sell"`
}

MatchSummary summarizes one or more consecutive matches at a given rate and buy/sell direction. Consecutive matches of the same rate and direction are binned by the server.

type Order

type Order struct {
	OrderID  order.OrderID
	Side     uint8
	Quantity uint64
	Rate     uint64
	Time     uint64
	// Epoch is only used in the epoch queue, otherwise it is ignored.
	Epoch uint64
}

Order represents an ask or bid.

type OrderBook

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

OrderBook represents a client tracked order book.

func NewOrderBook

func NewOrderBook(logger dex.Logger) *OrderBook

NewOrderBook creates a new order book.

func (*OrderBook) AddRecentMatches added in v0.6.0

func (ob *OrderBook) AddRecentMatches(matches [][2]int64, ts uint64) []*MatchSummary

AddRecentMatches adds the recent matches. If the recent matches cache length grows bigger than 100, it will slice out the ones first added.

func (*OrderBook) BaseFeeRate added in v0.2.0

func (ob *OrderBook) BaseFeeRate() uint64

BaseFeeRate is the last reported base asset fee rate.

func (*OrderBook) BestFill added in v0.2.0

func (ob *OrderBook) BestFill(sell bool, qty uint64) ([]*Fill, bool)

BestFill is the best (rate, quantity) fill for an order of the type and quantity specified. BestFill should be used when the exact quantity of base asset is known, i.e. limit orders and market sell orders. For market buy orders, use BestFillMarketBuy.

func (*OrderBook) BestFillMarketBuy added in v0.2.0

func (ob *OrderBook) BestFillMarketBuy(qty, lotSize uint64) ([]*Fill, bool)

BestFillMarketBuy is the best (rate, quantity) fill for a market buy order. The qty given will be in units of quote asset.

func (*OrderBook) BestNOrders

func (ob *OrderBook) BestNOrders(n int, side uint8) ([]*Order, bool, error)

BestNOrders returns the best n orders from the provided side. NOTE: This is UNUSED, and test coverage is a near dup of bookside_test.go.

func (*OrderBook) Book

func (ob *OrderBook) Book(note *msgjson.BookOrderNote) error

Book adds a new order to the order book.

func (*OrderBook) Enqueue

func (ob *OrderBook) Enqueue(note *msgjson.EpochOrderNote) error

Enqueue appends the provided order note to the corresponding epoch's queue.

func (*OrderBook) LogEpochReport added in v0.2.0

func (ob *OrderBook) LogEpochReport(note *msgjson.EpochReportNote) error

LogEpochReport is currently a no-op, and will update market history charts in the future.

func (*OrderBook) MidGap

func (ob *OrderBook) MidGap() (uint64, error)

MidGap returns the mid-gap price for the market. If one market side is empty the bets rate from the other side will be used. If both sides are empty, an error will be returned.

func (*OrderBook) Orders

func (ob *OrderBook) Orders() ([]*Order, []*Order, []*Order)

Orders is the full order book, as slices of sorted buys and sells, and unsorted epoch orders in the current epoch.

func (*OrderBook) QuoteFeeRate added in v0.2.0

func (ob *OrderBook) QuoteFeeRate() uint64

QuoteFeeRate is the last reported quote asset fee rate.

func (*OrderBook) RecentMatches added in v0.6.0

func (ob *OrderBook) RecentMatches() []*MatchSummary

RecentMatches returns up to 100 recent matches, newest first.

func (*OrderBook) Reset

func (ob *OrderBook) Reset(snapshot *msgjson.OrderBook) error

Reset forcibly updates a client tracked order book with an order book snapshot. This resets the sequence. TODO: eliminate this and half of the mutexes!

func (*OrderBook) Sync

func (ob *OrderBook) Sync(snapshot *msgjson.OrderBook) error

Sync updates a client tracked order book with an order book snapshot. It is an error if the the OrderBook is already synced.

func (*OrderBook) Unbook

func (ob *OrderBook) Unbook(note *msgjson.UnbookOrderNote) error

Unbook removes an order from the order book.

func (*OrderBook) UpdateRemaining

func (ob *OrderBook) UpdateRemaining(note *msgjson.UpdateRemainingNote) error

UpdateRemaining updates the remaining quantity of a booked order.

func (*OrderBook) ValidateMatchProof

func (ob *OrderBook) ValidateMatchProof(note msgjson.MatchProofNote) error

ValidateMatchProof ensures the match proof data provided is correct by comparing it to a locally generated proof from the same epoch queue.

type RemoteOrderBook

type RemoteOrderBook interface {
	// Sync instantiates a client tracked order book with the
	// current order book snapshot.
	Sync(*msgjson.OrderBook)
	// Book adds a new order to the order book.
	Book(*msgjson.BookOrderNote)
	// Unbook removes an order from the order book.
	Unbook(*msgjson.UnbookOrderNote) error
}

RemoteOrderBook defines the functions a client tracked order book must implement.

Jump to

Keyboard shortcuts

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