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:
- Send a book_lv2 subscription message.
- Receive a snapshot message from the server.
- Use an appropriate data structure to store the received book.
- 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.
- 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
| Parameter | Required | Type | Description |
|---|---|---|---|
| event | Yes | String | Operation: subscribe, unsubscribe |
| channel | Yes | Array | book_lv2 |
| symbols | Yes | Array | trading pair array |
Request Response
| Parameter | Type | Description |
|---|---|---|
| event | String | Operation: subscribe, unsubscribe |
| channel | String | book_lv2 |
| symbols | Array | trading pair array |
| message | String | Error message |
Push Data
| Parameter | Type | Description |
|---|---|---|
| channel | String | book_lv2 |
| data | Array | The subscribed data |
| > asks | Array | Buy order book |
| > bids | Array | Sell order book |
| > lid | Long | last version id |
| > id | Long | current version id |
| > ts | Long | Push time (millisecond) |
| > s | String | A trading pair |
| > cT | Long | create time |
| action | String | snapshot 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"
}