Documentation ¶
Index ¶
- Constants
- Variables
- type BooksFactory
- type Comparator
- type Condition
- type EventTradeSuccess
- type Kind
- type NopRepository
- type Order
- type OrderBook
- func (o *OrderBook) Add(ctx context.Context, order Order) (bool, error)
- func (o *OrderBook) Cancel(ctx context.Context, id string) error
- func (o *OrderBook) GetAsks() []Order
- func (o *OrderBook) GetBids() []Order
- func (o *OrderBook) GetStopAsks() []Order
- func (o *OrderBook) GetStopBids() []Order
- func (o *OrderBook) MarketPrice() apd.Decimal
- func (o *OrderBook) SetMarketPrice(ctx context.Context, price apd.Decimal, fPrice float64)
- type OrderTracker
- type Provider
- type Repository
- type Set
- func (set *Set) Add(tracker OrderTracker)
- func (set *Set) Find(id string) (OrderTracker, bool)
- func (set *Set) FindAllAsksAbove(price float64) []OrderTracker
- func (set *Set) FindAllBidsBelow(price float64) []OrderTracker
- func (set *Set) Iterator(side Side) treemap.ForwardIterator[OrderTracker, bool]
- func (set *Set) Len(side Side) int
- func (set *Set) Remove(id string)
- type Side
Constants ¶
View Source
const (
MinQty = 1
)
Variables ¶
View Source
var ( ErrInvalidQty = errors.New("invalid quantity provided") ErrInvalidTickerSymbol = errors.New("invalid ticker symbol") ErrInvalidMarketPrice = errors.New("price has to be zero for market orders") ErrInvalidLimitPrice = errors.New("price has to be set for limit orders") ErrInvalidStopPrice = errors.New("stop price has to be set for a stop order") ErrInternal = errors.New("internal error") )
Functions ¶
This section is empty.
Types ¶
type BooksFactory ¶
type BooksFactory struct { Mode string OrderRepo Repository }
func (*BooksFactory) Create ¶
func (config *BooksFactory) Create() map[string]*OrderBook
type Comparator ¶
type Comparator func(x, y OrderTracker) bool
type Condition ¶
type Condition int8
const ( ConditionStop Condition = 0x1 // stop order (has to have stop price set) ConditionAON Condition = 0x2 // all-or-nothing - complete fill or cancel ConditionIOC Condition = 0x4 // immediate-or-cancel - immediately fill what you can, cancel the rest ConditionFOK Condition = ConditionIOC | ConditionAON // immediately try to fill the whole order ConditionGTC Condition = 0x10 // good-till-cancelled - keep order active until manually cancelled ConditionGFD Condition = 0x20 // good-for-day keep order active until the end of the trading day ConditionGTD Condition = 0x40 // good-till-date - keep order active until the provided date (including the date) )
type EventTradeSuccess ¶
type Order ¶
type Order struct { ID string // this ticker symbol TickerSymbol string // CreatedAt means this order arrive time CreatedAt time.Time // the customer id CustomerID string Kind Kind // order kind - market or limit Params Condition // order parameters which change the way an order is stored and matched Qty int64 FilledQty int64 // currently filled quantity Price apd.Decimal // used in limit orders StopPrice apd.Decimal // used in stop orders Side Side // determines whether an order is a bid (buy) or an ask (sell) Cancelled bool // determines if an order is cancelled. A partially filled order can be cancelled. }
func (*Order) IsCancelled ¶
func (*Order) UnfilledQty ¶
type OrderBook ¶
type OrderBook struct { TickerSymbol string TradeEvents chan EventTradeSuccess // contains filtered or unexported fields }
func NewOrderBook ¶
func NewOrderBook(symbol string, marketPrice apd.Decimal, orderRepo Repository) *OrderBook
func (*OrderBook) Add ¶
Add a new order. Order can be matched immediately or later (or never), depending on order parameters and order type. Returns true if order was matched (partially or fully), false otherwise.
func (*OrderBook) GetStopAsks ¶
GetStopAsks Get all stop asks.
func (*OrderBook) GetStopBids ¶
GetStopBids Get all stop bids.
func (*OrderBook) MarketPrice ¶
MarketPrice Get a market price.
type OrderTracker ¶
type Provider ¶
type Provider interface { // Start process trade info Start(ctx context.Context) // SubmitOrder Submit order to order matching engine // Trade history will send by MQ when successful matching SubmitOrder(ctx context.Context, order Order) (err error) // ListAllAsks ist all asks orders. include Limit and Market orders ListAllAsks(ctx context.Context, symbol string) (orders []Order, err error) // ListAllBids List all bids orders include Limit and Market orders ListAllBids(ctx context.Context, symbol string) (orders []Order, err error) }
Provider define order service layer
type Repository ¶
type Repository interface { // FindOrder find order by id FindOrder(ctx context.Context, id string) (order *Order, err error) // SaveOrder save order SaveOrder(ctx context.Context, order *Order) (err error) }
Repository define order repository
type Set ¶
type Set struct { Bids *treemap.TreeMap[OrderTracker, bool] Asks *treemap.TreeMap[OrderTracker, bool] OrderTrackers map[string]OrderTracker }
func NewOrderSet ¶
func NewOrderSet(bidComparator Comparator, askComparator Comparator) *Set
func (*Set) Add ¶
func (set *Set) Add(tracker OrderTracker)
func (*Set) FindAllAsksAbove ¶
func (set *Set) FindAllAsksAbove(price float64) []OrderTracker
FindAllAsksAbove ask orders below or equal the price, sorted by time ast
func (*Set) FindAllBidsBelow ¶
func (set *Set) FindAllBidsBelow(price float64) []OrderTracker
FindAllBidsBelow bids orders above or equal the price, sorted by time ast
func (*Set) Iterator ¶
func (set *Set) Iterator(side Side) treemap.ForwardIterator[OrderTracker, bool]
Iterator which iterates through sorted bids or asks.
Click to show internal directories.
Click to hide internal directories.