Orderbook
Subscribe to the orderbook stream. Supports different depths.
tip
- Once you have subscribed successfully, you will receive a
snapshot
. - The WebSocket will keep pushing
delta
messages every time the orderbook changes. If you receive a newsnapshot
message, you will have to reset your local orderbook. - If there is a problem on Zoomex's end, a
snapshot
will be re-sent, which is guaranteed to contain the latest data.
info
Linear & inverse level 1 data: if 3 seconds have elapsed without a change in the orderbook, a snapshot
message will be pushed again.
Linear & inverse:
Level 1 data, push frequency: 10ms
Level 50 data, push frequency: 20ms
Level 200 data, push frequency: 100ms
Level 500 data, push frequency: 100ms
Spot:
Level 1 data, push frequency: 10ms
Level 50 data, push frequency: 20ms
Level 200 data, push frequency: 200ms
Topic:
orderbook.{depth}.{symbol}
e.g., orderbook.1.BTCUSDT
Response Parameters
Parameter | Type | Comments |
---|---|---|
topic | string | Topic name |
type | string | Data type. snapshot ,delta |
ts | number | The timestamp (ms) that the system generates the data |
data | array | Object |
> s | string | Symbol name |
> b | array | Bids. For snapshot stream, the element is sorted by price in descending order |
>> b[0] | string | Bid price |
>> b[1] | string | Bid size |
> a | array | Asks. For snapshot stream, the element is sorted by price in ascending order |
>> a[0] | string | Ask price |
>> a[1] | string | Ask size |
> u | integer | Update ID. Is a sequence. Occasionally, you'll receive "u"=1, which is a snapshot data due to the restart of the service. So please overwrite your local orderbook |
> seq | integer | Cross sequence. |
cts | number | The timestamp from the match engine when this orderbook data is produced. It can be correlated with T from public trade channel |
Subscribe Example
// 创建WebSocket对象
const socket = new WebSocket('wss://stream-testnet.zoomex.com/v3/public/linear');
// 订阅WebSocket
socket.onopen = function() {
console.log('WebSocket连接已经打开');
// 发送订阅消息
const subscribeMsg = {
"op": "subscribe",
"args": ["orderbook.50.BTCUSDT"]
};
socket.send(JSON.stringify(subscribeMsg));
};
// 监听WebSocket消息
socket.onmessage = function(event) {
console.log('收到WebSocket消息:', event.data);
};
// 监听WebSocket关闭事件
socket.onclose = function(event) {
console.log('WebSocket连接已经关闭', event);
};
Response Example
- Snapshot
- Delta
{
"topic": "orderbook.50.BTCUSDT",
"type": "snapshot",
"ts": 1672304484978,
"data": {
"s": "BTCUSDT",
"b": [
...,
[
"16493.50",
"0.006"
],
[
"16493.00",
"0.100"
]
],
"a": [
[
"16611.00",
"0.029"
],
[
"16612.00",
"0.213"
],
...,
],
"u": 18521288,
"seq": 7961638724
}
}
{
"topic": "orderbook.50.BTCUSDT",
"type": "delta",
"ts": 1687940967466,
"data": {
"s": "BTCUSDT",
"b": [
[
"30247.20",
"30.028"
],
[
"30245.40",
"0.224"
],
[
"30242.10",
"1.593"
],
[
"30240.30",
"1.305"
],
[
"30240.00",
"0"
]
],
"a": [
[
"30248.70",
"0"
],
[
"30249.30",
"0.892"
],
[
"30249.50",
"1.778"
],
[
"30249.60",
"0"
],
[
"30251.90",
"2.947"
],
[
"30252.20",
"0.659"
],
[
"30252.50",
"4.591"
]
],
"u": 177400507,
"seq": 66544703342
}
}