orderbook

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2020 License: MIT Imports: 5 Imported by: 0

README

Orderbook

Circle CI Docs Go Report Version

Overview

⚡ High speed matching engine

License

Project released under the terms of the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateLocked

func CalculateLocked(amount, price decimal.Decimal, side Side) decimal.Decimal

CalculateLocked calculates locked according to order side.

Types

type Engine

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

Engine is core structure for matching engine.

func New

func New() *Engine

New creates new order-book engine.

func (*Engine) Cancel

func (e *Engine) Cancel(order *Order) *Order

Cancel removes order from order-book.

func (*Engine) Match

func (e *Engine) Match(order *Order) ([]Trade, *Order, error)

Match matches upcoming order with orders in order-book.

func (*Engine) Print

func (e *Engine) Print(w io.Writer)

Print prints order-book into io.Writer.

func (*Engine) String

func (e *Engine) String() string

String returns orders from order-book. Returns list of buy orders, then sell orders.

type Kind

type Kind string

Kind of order, either "Market" or "Limit". New types of order can be added.

const (
	// KindMarket is representation of Market order.
	KindMarket Kind = "market"
	// KindLimit is representation of Limit order.
	KindLimit Kind = "limit"
)

type Order

type Order struct {
	ID       uint64          `json:"id"`
	Side     Side            `json:"side"`
	Kind     Kind            `json:"kind"`
	Price    decimal.Decimal `json:"price"`
	Volume   decimal.Decimal `json:"volume"`
	Locked   decimal.Decimal `json:"locked"`
	Received decimal.Decimal `json:"received"`
}

Order is simple representation of order for matching engine.

func (*Order) Less

func (o *Order) Less(other btree.Item) bool

Less compares two orders by price & ID, respects order Side. Used in order-book for sorting btree of orders.

type Side

type Side string

Side of order, either "sell" or "buy".

const (
	// SideSell is representation of sell Side.
	SideSell Side = "sell"
	// SideBuy is representation of buy Side.
	SideBuy Side = "buy"
)

type Trade

type Trade struct {
	Buy    Order           `json:"buy"`
	Sell   Order           `json:"sell"`
	Amount decimal.Decimal `json:"amount"`
	Price  decimal.Decimal `json:"price"`
}

Trade is result of two matched orders.

func NewTrade

func NewTrade(buy, sell *Order, amount, price decimal.Decimal) *Trade

NewTrade creates new trade.

Jump to

Keyboard shortcuts

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