exchange

package
v0.0.0-...-9e4a7a5 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxPrice      Price = 100_000
	MinPrice      Price = 1
	EstNumOrders  Size  = 1_000_000 // Rough estimate of number of orders (to pre-allocate orderIDMap)
	EstNumSymbols Size  = 1_000     // Rough estimate of number of symbols (to pre-allocate orderbooksMap)
	ChanSize      Size  = 10_000    // Channel buffer size
)

Define the constants used in the exchange These are used to provide bounds for the exchange and pre-allocate memory

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

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

Action represents an action event passed by the exchange

func (*Action) String

func (action *Action) String() string

String returns a string representation of the action, used for logging

type ActionType

type ActionType uint8

ActionType represents the type of action event passed by the exchange

const (
	ActionBid ActionType = iota
	ActionAsk
	ActionOrderReject
	ActionCancel
	ActionCancelReject
	ActionExecute
)

Define the action types used in the exchange for various order event states

type Exchange

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

Exchange represents the exchange engine, that stores the orderbooks (per symbol) and manages the orders

func (*Exchange) Cancel

func (ex *Exchange) Cancel(orderID OrderID)

Cancel processes an incoming cancel order, cancelling the order if it exists in the exchange

func (*Exchange) Init

func (ex *Exchange) Init(name string, actions chan *Action)

Init initialises the exchange with the given name and actions channel, and establishes the order storage

func (*Exchange) Limit

func (ex *Exchange) Limit(symbol string, price Price, size Size, side Side, trader TraderID)

Limit processes an incoming limit order, validating it and passing it to the appropriate orderbook

func (*Exchange) PreWarmWithSymbols

func (ex *Exchange) PreWarmWithSymbols(symbols []string)

PreWarmWithSymbols 'pre-warms' the exchange with the given symbols, creating the orderbooks Used to avoid the first order for a symbol being slow due to orderbook creation

type Order

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

Order represents an order on the exchange

type OrderBook

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

OrderBook represents the collection of asks and bids, for a specific symbol on the exchange

type OrderID

type OrderID uint64 // Unique identifier for an order [range 0-2^64]

Define the types used in the exchange. These are used to represent the orderbook, orders, and traders

type Price

type Price uint32 // Price in ticks (eg. 12345 would be 123.45) [range 0-2^32]

type PricePoint

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

PricePoint represents a price level and its associated orders Deque in the orderbook

func (*PricePoint) Less

func (p *PricePoint) Less(than btree.Item) bool

Less is used by the btree package to compare PricePoints and allow nodes to be stored correctly

type Side

type Side uint8 // Bid or Ask
const (
	Bid Side = iota // Bid side represents a buy order
	Ask             // Ask side represents a sell order
)

Define the two sides of an order

type Size

type Size uint32 // Size integer [range 0-2^32]

type TraderID

type TraderID uint16 // Unique identifier for a trader [range 0-2^16]

Jump to

Keyboard shortcuts

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