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 Bybit'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

Option:
Level 25 data, push frequency: 20ms
Level 100 data, push frequency: 100ms

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
datamapObject
> 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

    from pybit.unified_trading import WebSocket
    from time import sleep
    ws = WebSocket(
    testnet=True,
    channel_type="linear",
    )
    def handle_message(message):
    print(message)
    ws.orderbook_stream(
    depth=50,
    symbol="BTCUSDT",
    callback=handle_message
    )
    while True:
    sleep(1)

    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
    }
    "cts": 1672304484976
    }