Documentation ¶
Overview ¶
Package fastme package implements limit matching engine. To process order you need to implement following interfaces
Index ¶
- Variables
- type Asset
- type Engine
- func (e *Engine) CanPlace(ctx context.Context, w Wallet, sell bool, quantity, price Value) error
- func (e *Engine) CancelOrder(ctx context.Context, listener EventListener, o Order)
- func (e *Engine) FindOrder(id string) (Order, error)
- func (e *Engine) OrderBook(iter func(asks bool, price, volume Value, len int))
- func (e *Engine) Orders() (orders []Order)
- func (e *Engine) PlaceOrder(ctx context.Context, listener EventListener, o Order) (err error)
- func (e *Engine) Price(sell bool, quantity Value) (Value, error)
- func (e *Engine) PushOrder(ctx context.Context, o Order)
- func (e *Engine) Quantity(sell bool, priceLim Value) Value
- func (e *Engine) ReplaceOrder(ctx context.Context, listener EventListener, o, n Order) error
- func (e *Engine) SetFeeHandler(h FeeHandler)
- func (e *Engine) Spread() (bestAsk, bestBid Value)
- type EventListener
- type FeeHandler
- type Order
- type Value
- type Volume
- type Wallet
Constants ¶
This section is empty.
Variables ¶
var ( //lint:ignore ST1005 for backward compatibility ErrInvalidQuantity = errors.New("Invalid order quantity") //lint:ignore ST1005 for backward compatibility ErrInvalidPrice = errors.New("Invalid order price") //lint:ignore ST1005 for backward compatibility ErrInvalidOrder = errors.New("Invalid order format") //lint:ignore ST1005 for backward compatibility ErrInsufficientQuantity = errors.New("Insufficient quantity to calculate market price") //lint:ignore ST1005 for backward compatibility ErrInsufficientFunds = errors.New("Insufficient funds to process order") ErrOrderExists = errors.New("Order with given ID already exists") ErrOrderNotFound = errors.New("Order with given ID not found") )
Fast matching engine errors
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine implements fast matching engine
func NewEngineWithFeeHandler ¶ added in v1.3.0
func NewEngineWithFeeHandler(base, quote Asset, h FeeHandler) (me *Engine)
NewEngineWithFeeHandler creates fast matching engine implementation
func (*Engine) CanPlace ¶ added in v1.2.0
CanPlace calculates balance and retuns an error if is not enought money to place an order with given params
func (*Engine) CancelOrder ¶
func (e *Engine) CancelOrder( ctx context.Context, listener EventListener, o Order, )
CancelOrder removes order from the order book and refund assets to the owner
func (*Engine) OrderBook ¶
OrderBook returns information about volume and price for definite price level
func (*Engine) PlaceOrder ¶
PlaceOrder order adds the order to the order book and solves exchange task
func (*Engine) ReplaceOrder ¶ added in v1.1.0
ReplaceOrder replaces order at the same price level without queue loss
func (*Engine) SetFeeHandler ¶
func (e *Engine) SetFeeHandler(h FeeHandler)
SetFeeHandler updates fee handlers
type EventListener ¶
type EventListener interface { OnIncomingOrderPartial(context.Context, Order, Volume) OnIncomingOrderDone(context.Context, Order, Volume) OnIncomingOrderPlaced(context.Context, Order) OnExistingOrderPartial(context.Context, Order, Volume) OnExistingOrderDone(context.Context, Order, Volume) OnExistingOrderCanceled(context.Context, Order) OnBalanceChanged(context.Context, Wallet, Asset, Value) OnInOrderChanged(context.Context, Wallet, Asset, Value) }
EventListener informs subscriber to some matching changes
type FeeHandler ¶
type FeeHandler interface { // HandleFeeMaker calls by matching engine and provide data to correct output value for fee processing HandleFeeMaker(context.Context, Order, Asset, Value) (out Value) // HandleFeeTaker calls by matching engine and provide data to correct output value for fee processing HandleFeeTaker(context.Context, Order, Asset, Value) (out Value) }
FeeHandler responsible for fee calculations and fee wallet processing
type Order ¶
type Order interface { // ID returns any uinique string for order ID() string // Owner returns wallet to debit or credit asset on exchange process Owner() Wallet // Sell returns true if order for selling, true otherwise Sell() bool // Price returns order price Price() Value // Quantity returns current order quantity Quantity() Value // UpdateQuantity calls by matching engine to set new order quantity UpdateQuantity(Value) }
Order is the extensible interface responsible for containing information about order
type Value ¶
type Value interface { // Add is an "+" operation Add(Value) Value // Sub is an "-" operation Sub(Value) Value // Mul is an "*" operation Mul(Value) Value // Cmp returns 1 if self > given, -1 if self < given and 0 if self == given Cmp(Value) int // Sign returns 1 if Value > 0, -1 if Value < 0 and 0 if Value == 0 Sign() int // Hash returns any string representation of the Value Hash() string }
Value calcultes math operations
type Wallet ¶
type Wallet interface { // Balance returns current wallet balance for given asset Balance(context.Context, Asset) Value // UpdateBalance calls by matching engine to update wallet balance UpdateBalance(context.Context, Asset, Value) // InOrder returns amount of asset in order (optional) InOrder(context.Context, Asset) Value // UpdateInOrder calls by matching engine to inform about freezed amount in order (optional) UpdateInOrder(context.Context, Asset, Value) }
Wallet describes interface for asset exchange operations