Market Depth Subscription
Info
- The push delay of this method is about:200ms
Market Depth Subscription
- Method:
depth.subscribe
- Parameters:
Parameter Name | Required | Type | Notes |
---|---|---|---|
market_list[n][0] | true | string | market name. |
market_list[n][1] | true | int | limit, number of push depth items, one of [5, 10, 20, 50] |
market_list[n][2] | true | string | interval, merge interval, one of ["0", "0.00000000001", "0.000000000001", "0.0000000001", "0.000000001", "0.00000001", "0.0000001", "0.000001", "0.00001", "0.00 01", "0.001", "0.01", "0.1", "1", "10", "100", "1000"] |
market_list[n][3] | true | bool | if_full, whether it is a full subscription |
- Subscription example
{
"method": "depth.subscribe",
"params": {"market_list": [
["BTCUSDT", 10, "0", true],
["ETHUSDT", 10, "0", false]
]
},
"id": 1
}
Depth Push
- Method:
depth.update
- Parameters:
Parameter Name | Type | Notes |
---|---|---|
market | string | Market name |
is_full | bool | True means full push, and false means incremental push |
depth | object | Depth data |
depth.asks | array | Seller data |
asks[n][0] | string | Seller price |
asks[n][1] | string | Seller size. During incremental push, a value of 0 indicates the depth at which the price needs to be deleted. |
depth.bids | array | Buyer data |
bids[n][0] | string | Buyer price |
bids[n][1] | string | Buyer size. During incremental push, a value of 0 indicates the depth at which the price needs to be deleted. |
depth.last | string | Latest price |
depth.updated_at | int | Timestamp, millisecond |
depth.checksum | string | Data checksum |
Reminder
About incremental and full depth push:
- Incremental push: Each push delivers the depth data updated from the last push to the present time.In every 200 milliseconds. No push if there is no depth update.
- Full push: Each push delivers the complete depth data.In every 200 milliseconds. No push if there is no depth update.
- For multiple market subscriptions, use the market params to separate push messages in different markets.
- Full market depth push is delivered every 1 minute.
About Depth Checksum:
- The checksum is a signed 32-bit integer of the full depth data, used to verify the accuracy of the depth data.
- Construct the checksum string: bid1_price:bid1_amount:bid2_price:bid2_amount:ask1_price:ask1_amout:... (if there is no bid, the checksum string will be ask1_price:ask1_amount:ask2_price:ask2_amount:...)
- Encode the checksum string using crc32 algorithm
Please check out the Code Examples to see how to use both full and incremental data pushes in the API client to recover complete depth data and verify its accuracy.
- Push example
{
"method": "depth.update",
"data": {
"market": "BTCUSDT",
"is_full": true,
"depth": {
"asks": [
[
"30740.00",
"0.31763545"
],
[
"30769.00",
"1.45155000"
]
],
"bids": [
[
"30736.00",
"0.04857373"
],
[
"30733.00",
"0.84696320"
],
[
"30725.00",
"0.12563353"
],
[
"30422.00",
"0"
]
],
"last": "30746.28",
"updated_at": 1689152421692,
"checksum": 2578768879
}
},
"id": null
}
Cancel Market Depth Subscription
- Method:
depth.unsubscribe
- Parameters:
Parameter Name | Required | Type | Notes |
---|---|---|---|
market_list | true | []string | List of market names. Empty list to unsubscribe to all markets. |
- Unsubscribe example:
// unsubscribe to singular market depth
{
"method": "depth.unsubscribe",
"params": {"market_list": ["BTCUSDT"]},
"id": 1
}
// unsubscribe to multiple market depths
{
"method": "depth.unsubscribe",
"params": {"market_list": ["BTCUSDT", "ETHUSDT"]},
"id": 1
}
// unsubscribe to all market depths
{
"method": "depth.unsubscribe",
"params": {"market_list": []},
"id": 1
}