Skip to main content

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 new snapshot 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

ParameterTypeComments
topicstringTopic name
typestringData type. snapshot,delta
tsnumberThe timestamp (ms) that the system generates the data
dataarrayObject
> sstringSymbol name
> barrayBids. For snapshot stream, the element is sorted by price in descending order
>> b[0]stringBid price
>> b[1]stringBid size
  • The delta data has size=0, which means that all quotations for this price have been filled or cancelled
  • > aarrayAsks. For snapshot stream, the element is sorted by price in ascending order
    >> a[0]stringAsk price
    >> a[1]stringAsk size
  • The delta data has size=0, which means that all quotations for this price have been filled or cancelled
  • > uintegerUpdate 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
    > seqintegerCross sequence.
  • You can use this field to compare different levels orderbook data, and for the smaller seq, then it means the data is generated earlier.
  • ctsnumberThe 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

    {
    "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
    }
    }