深度
訂閱不同深度的推送
提示
- 訂閱成功後,會立即得到一個當前快照包的推送消息.
- websocket將會繼續推送這些增量數據. 收到snapshot的報文,就需要重置本地的orderbook.
snapshot
=全量orderbook,delta
=增量orderbook- 如果因為Bybit服務原因,會重新發送snapshot報文,該報文已保證是最新且準確的.
信息
USDT永續, USDC永續, USDC交割 & 反向合約 1檔數據: 若3秒內無變化, 將會再次推送snapshot數據, 此消息中的字段u
和前一條消息裡的“u”保持一樣
USDT和USDC永續 & 反向合約:
1 檔數據, 推送頻率: 10ms
50 檔數據, 推送頻率: 20ms
200 檔數據, 推送頻率: 100ms
500 檔數據, 推送頻率: 100ms
現貨:
1 檔數據, 推送頻率: 10ms
50 檔數據, 推送頻率: 20ms
200 檔數據, 推送頻率: 200ms
期權:
25 檔數據, 推送頻率: 20ms
100 檔數據, 推送頻率: 100ms
Topic:
orderbook.{depth}.{symbol}
e.g., orderbook.1.BTCUSDT
響應參數
參數 | 類型 | 說明 |
---|---|---|
topic | string | Topic名 |
type | string | 數據類型. snapshot ,delta |
ts | number | 行情服務生成數據的時間戳 (毫秒) |
data | map | Object |
> s | string | 合約名稱 |
> b | array | Bid, 買方. snapshot 數據,是按照價格從大到小 |
>> b[0] | string | 買方報價 |
>> b[1] | string | 買方數量 |
> a | array | Ask, 賣方. snapshot 數據,是按照價格從小到大 |
>> a[0] | string | 賣方報價 |
>> a[1] | string | 賣方數量 |
> u | integer | 更新id |
> seq | integer | 撮合版本號 |
cts | number | 產生此訂單簿數據時來自撮合引擎的時間戳. 可用於與平台成交頻道中的T 進行關聯 |
訂閱示例
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)
響應示例
- 全量
- 增量
{
"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
}
{
"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"
],
[
"30248.90",
"3.525"
],
[
"30249.00",
"2.327"
],
[
"30249.60",
"0"
],
[
"30249.80",
"2.178"
],
[
"30249.90",
"4.685"
],
[
"30250.00",
"9.907"
],
[
"30250.10",
"1.070"
],
[
"30251.60",
"2.239"
],
[
"30251.90",
"2.947"
],
[
"30252.20",
"0.659"
],
[
"30252.50",
"4.591"
]
],
"u": 177400507,
"seq": 66544703342
}
"cts": 1687940967464
}