Skip to main content

Order Book Level 2

Description

Receive a snapshot of the full 20 level order book. Then, continuously in realtime receive an updated order book when the first 20 levels change.

To maintain a copy of the order book locally:

  1. Send a book_lv2 subscription message.
  2. Receive a snapshot message from the server.
  3. Use an appropriate data structure to store the received book.
  4. Receive an incremental order book message (update) from the server and make changes depending on [price, quantity] pair data:
    • When quantity is positive, update the corresponding price of your order book with this quantity.
    • When quantity is 0, delete this price from your order book.
  5. Receive an order book message (snapshot) from the server, reset your order book data structure to match this new order book.

Note: If id of the last message does not match lid of the current message then the client has lost connection with the server and must re-subscribe to the channel.

Pushing Frequency

Real Time

Channel

book_lv2

Request Parameters

ParameterRequiredTypeDescription
eventYesStringOperation: subscribe, unsubscribe
channelYesArraybook_lv2
symbolsYesArraytrading pair array

Request Response

ParameterTypeDescription
eventStringOperation: subscribe, unsubscribe
channelStringbook_lv2
symbolsArraytrading pair array
messageStringError message

Push Data

ParameterTypeDescription
channelStringbook_lv2
dataArrayThe subscribed data
> asksArrayBuy order book
> bidsArraySell order book
> lidLonglast version id
> idLongcurrent version id
> tsLongPush time (millisecond)
> sStringA trading pair
> cTLongcreate time
actionStringsnapshot full push, update incremental update

Request Example

{
"event": "subscribe",
"channel": ["book_lv2"],
"symbols": ["BTC_USDT_PERP"]
}

Push Data Example

{
"channel": "book_lv2",
"data": [
{
"asks": [["46100", "9284"]],
"bids": [["34400.089", "1"]],
"lid": 953,
"id": 954,
"ts": 1718870001418,
"s": "BTC_USDT_PERP",
"cT": 1718869676555
}
],
"action": "snapshot"
}