matcher

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: BlueOak-1.0.0 Imports: 9 Imported by: 1

Documentation

Index

Constants

View Source
const (
	HashSize = blake256.Size
)

Variables

View Source
var (
	HashFunc    = blake256.Sum256
	BaseToQuote = calc.BaseToQuote
	QuoteToBase = calc.QuoteToBase
)

HashFunc is the hash function used to generate the shuffling seed.

Functions

func CSum

func CSum(queue []order.Order) []byte

CSum computes the commitment checksum for the order queue. For an empty queue, the result is a nil slice instead of the initial hash state.

func CheckMarketBuyBuffer

func CheckMarketBuyBuffer(book Booker, ord *order.MarketOrder, marketBuyBuffer float64) bool

CheckMarketBuyBuffer verifies that the given market buy order's quantity (specified in quote asset) is sufficient according to the Matcher's configured market buy buffer, which is in base asset units, and the best standing sell order according to the provided Booker.

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.

func OrdersMatch

func OrdersMatch(a, b order.Order) bool

OrdersMatch checks if two orders are valid matches, without regard to quantity. - not a cancel order - not two market orders - orders on different sides (one buy and one sell) - two limit orders with overlapping rates, or one market and one limit

func ShuffleQueue

func ShuffleQueue(queue []*OrderRevealed)

func UseLogger

func UseLogger(logger slog.Logger)

UseLogger uses a specified Logger to output package logging info.

Types

type Booker

type Booker interface {
	LotSize() uint64
	BuyCount() int
	SellCount() int
	BestSell() *order.LimitOrder
	BestBuy() *order.LimitOrder
	Insert(*order.LimitOrder) bool
	Remove(order.OrderID) (*order.LimitOrder, bool)
	BuyOrders() []*order.LimitOrder
	SellOrders() []*order.LimitOrder
}

Booker should be implemented by the order book.

type MatchCycleStats added in v0.2.0

type MatchCycleStats struct {
	MatchVolume uint64
	QuoteVolume uint64
	BookSells   uint64
	BookBuys    uint64
	BookSells5  uint64
	BookBuys5   uint64
	BookSells25 uint64
	BookBuys25  uint64
	HighRate    uint64
	LowRate     uint64
	StartRate   uint64
	EndRate     uint64
}

MatchCycleStats is data about the results of a match cycle.

type Matcher

type Matcher struct{}

func New

func New() *Matcher

New creates a new Matcher.

func (*Matcher) Match

func (m *Matcher) Match(book Booker, queue []*OrderRevealed) (seed []byte, matches []*order.MatchSet,
	passed, failed, doneOK, partial, booked, nomatched []*OrderRevealed,
	unbooked []*order.LimitOrder, updates *OrdersUpdated, stats *MatchCycleStats)

Match matches orders given a standing order book and an epoch queue. Matched orders from the book are removed from the book. The EpochID of the MatchSet is not set. passed = booked + doneOK. queue = passed + failed. unbooked may include orders that are not in the queue. Each of partial are in passed. nomatched are orders that did not match anything, and discludes booked limit orders that only matched as makers to down-queue takers.

TODO: Eliminate order slice return args in favor of just the *OrdersUpdated.

type OrderRevealed

type OrderRevealed struct {
	Order    order.Order // Do not embed so OrderRevealed is not an order.Order.
	Preimage order.Preimage
}

OrderRevealed combines an Order interface with a Preimage.

type OrdersUpdated

type OrdersUpdated struct {
	// CancelsExecuted are cancel orders that were matched to and removed
	// another order from the book.
	CancelsExecuted []*order.CancelOrder
	// CancelsFailed are cancel orders that failed to match and cancel an order.
	CancelsFailed []*order.CancelOrder

	// TradesFailed are unmatched and unbooked (i.e. unmatched market or limit
	// with immediate time-in-force), or orders with bad lot size. These orders
	// will be in no other slice.
	TradesFailed []order.Order

	// TradesBooked are limit orders from the epoch queue that were put on the
	// book. Because of downstream epoch processing, these may also be in
	// TradesPartial, and TradesCompleted or TradesCanceled.
	TradesBooked []*order.LimitOrder
	// TradesPartial are limit orders that were partially filled as maker orders
	// (while on the book). Epoch orders that were partially filled prior to
	// being booked (while takers) are not necessarily in TradesPartial unless
	// they are filled again by a taker. This is because all status updates also
	// update the filled amount.
	TradesPartial []*order.LimitOrder
	// TradesCanceled are limit orders that were removed from the the book by a
	// cancel order. These may also be in TradesBooked and TradesPartial, but
	// not TradesCompleted.
	TradesCanceled []*order.LimitOrder
	// TradesCompleted are market or limit orders that filled to completion. For
	// a market order, this means it had a match that partially or completely
	// filled it. For a limit order, this means the time-in-force is immediate
	// with at least one match for any amount, or the time-in-force is standing
	// and it is completely filled.
	TradesCompleted []order.Order
}

OrdersUpdated represents the orders updated by (*Matcher).Match, and may include orders from both the epoch queue and the book. Trade orders that are not in TradesFailed may appear in multiple other trade order slices, so update them in sequence: booked, partial, and finally completed or canceled. Orders in TradesFailed will not be in another slice since failed indicates unmatched&unbooked or bad lot size. Cancel orders may only be in one of CancelsExecuted or CancelsFailed.

func (*OrdersUpdated) String

func (ou *OrdersUpdated) String() string

Directories

Path Synopsis
Package mt19937 implements the 64-bit version of the Mersenne Twister (MT) pseudo-random number generator (PRNG) with a period of 2^19937-1, also known as mt19937_64, according to the reference implementation by Matsumoto and Nishimura at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html
Package mt19937 implements the 64-bit version of the Mersenne Twister (MT) pseudo-random number generator (PRNG) with a period of 2^19937-1, also known as mt19937_64, according to the reference implementation by Matsumoto and Nishimura at http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt64.html

Jump to

Keyboard shortcuts

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