# L2 Trading api L2 Trade Binary protocol is a modified version of NASDAQ OUCH 4.2 protocol. Some information about L2A Trade Binary protocol can be found in NASDAQ OUCH 4.2 specification. Almost a copy of this specification is presented below (including L2A specific modifications). ### 1. messages sent from a trader to the broker(inbound messages) 0. Types of messages. ```go const ( CreateOrderType = types.Char('O') UpdateOrderType = types.Char('U') CancelOrderType = types.Char('C') SetOrderLeverageType = types.Char('L') ) ``` 1. Lengths of messages(should stay separated initialized as constants). ```go const ( CreateOrderLength int = 103 UpdateOrderLength int = 102 CancelOrderLength int = 86 SetOrderLeverageLength int = 80 ) ``` * CreateOrder is containing Create Order Message fields in useable format. ```go type CreateOrder struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` OrderCID types.Uint64 `json:"order_client_id"` OrderType types.Char `json:"order_type"` Price types.Uint64 `json:"price"` Quantity types.Uint64 `json:"quantity"` AccountID types.Uint64 `json:"account_id"` Signature types.Signature `json:"signature"` } ``` * CancelOrder is containing Cancel Order Message fields in useable format. ```go type CancelOrder struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` OrderID types.Uint64 `json:"order_id"` AccountID types.Uint64 `json:"account_id"` Signature types.Signature `json:"signature"` } ``` * SetOrderLeverage is containing SetOrderLeverage message fields in useable format. ```go type SetOrderLeverage struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` Leverage types.Char `json:"leverage"` Side types.Char `json:"side"` AccountID types.Uint64 `json:"account_id"` Signature types.Signature `json:"signature"` } ``` * UpdateOrder is a structure containing Update Order Message fields in usable format. ```go type UpdateOrder struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` OrderID types.Uint64 `json:"order_id"` Price types.Uint64 `json:"price"` Quantity types.Uint64 `json:"quantity"` AccountID types.Uint64 `json:"account_id"` Signature types.Signature `json:"signature"` } ``` ### 2. messages sent from the broker to a trader (outbound messages) 0. Types of messages ```go const ( OrderCreatedType = types.Char('O') OrderUpdatedType = types.Char('U') OrderCancelledType = types.Char('C') LeverageOrderSetType = types.Char('L') OrderAcceptedType = types.Char('Y') OrderRejectedType = types.Char('R') OrderExecutedType = types.Char('E') ErrorType = types.Char('!') ) ``` 1. Lengths of messages(should stay separated initialized as constants) ```go const ( OrderCreatedLength int = 52 OrderUpdatedLength int = 43 OrderCancelledLength int = 27 LeverageOrderSetLength int = 21 OrderAcceptedLength int = 35 OrderRejectedLength int = 36 OrderExecutedLength int = 44 ErrorLength int = 13 ) ``` * OrderAccepted is containing Order Accepted Event fields in useable format. ```go type OrderAccepted struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` OrderCID types.Uint64 `json:"order_client_id"` OrderID types.Uint64 `json:"order_id"` AccountID types.Uint64 `json:"account_id"` Timestamp types.Timestamp `json:"timestamp"` } ``` * Error is containing Error Event fields in useable format. ```go type Error struct { MessageType types.Char `json:"message_type"` Timestamp types.Timestamp `json:"timestamp"` Code types.Uint16 `json:"code"` MessageLength types.Uint16 `json:"message_length"` Message types.String `json:"message"` } ``` * OrderCancelled is containing Order Cancelled Event fields in useable format. ```go type OrderCancelled struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` OrderID types.Uint64 `json:"order_id"` AccountID types.Uint64 `json:"account_id"` // TODO: Is it better to remove from here? Timestamp types.Timestamp `json:"timestamp"` } ``` * LeverageOrderSet is containing Leverage Order Set Event fields in useable format. ```go type LeverageOrderSet struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` Leverage types.Char `json:"leverage"` Side types.Char `json:"side"` AccountID types.Uint64 `json:"account_id"` Timestamp types.Timestamp `json:"timestamp"` } ``` * OrderCreated is containing Order Created Event fields in useable format. ```go type OrderCreated struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` OrderCID types.Uint64 `json:"order_client_id"` OrderID types.Uint64 `json:"order_id"` OrderType types.Char `json:"order_type"` Price types.Uint64 `json:"price"` Quantity types.Uint64 `json:"quantity"` AccountID types.Uint64 `json:"account_id"` Timestamp types.Timestamp `json:"timestamp"` } ``` * OrderExecuted is containing Order Executed Event fields in useable format. ```go type OrderExecuted struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` MakerOrderID types.Uint64 `json:"maker_order_id"` TakerOrderID types.Uint64 `json:"taker_order_id"` ExecutedPrice types.Uint64 `json:"executed_price"` ExecutedQuantity types.Uint64 `json:"executed_quantity"` IsBuyerMaker types.Char `json:"is_buyer_maker"` Timestamp types.Timestamp `json:"timestamp"` } ``` * OrderRejected is a structure containing Order Rejected Event fields in useable format. ```go type OrderRejected struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` OrderCID types.Uint64 `json:"order_client_id"` OrderID types.Uint64 `json:"order_id"` AccountID types.Uint64 `json:"account_id"` Timestamp types.Timestamp `json:"timestamp"` Reason types.Char `json:"reason"` } ``` * OrderUpdated is containing Order Updated Event fields in useable format. ```go type OrderUpdated struct { MessageType types.Char `json:"message_type"` SymbolID types.Uint16 `json:"symbol_id"` OrderID types.Uint64 `json:"order_id"` Price types.Uint64 `json:"price"` Quantity types.Uint64 `json:"quantity"` AccountID types.Uint64 `json:"account_id"` Timestamp types.Timestamp `json:"timestamp"` } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up