跳转至

WebSocket 实时推送

目标

说明 APP 专属 WSS 实时推送接口的鉴权和基本接入方式。

鉴权方式

WebSocket 接口使用与 HTTP API 相同的签名体系:

  • Authorization
  • X-Timestamp
  • X-Nonce
  • X-Signature
Header 示例
Authorization Bearer <token>
X-Timestamp 1771129750
X-Nonce deb9623a3584bf054d96288f2ebaad76
X-Signature 7d913d394e8b804d1bd4bede97434309

Python 接入示例

import websocket
import hashlib
import time
import json

token = "your_token_here"
url = "wss://stock-data-api.aibot6.cn/ws/monitor/bigdata/?code=600000&day=20260213"

ts = str(int(time.time()))
nonce = hashlib.md5(str(time.time()).encode("utf-8")).hexdigest()
sign = hashlib.md5((token + ts + nonce).encode("utf-8")).hexdigest()

headers = [
    f"Authorization: Bearer {token}",
    f"X-Timestamp: {ts}",
    f"X-Nonce: {nonce}",
    f"X-Signature: {sign}",
]

ws = websocket.create_connection(url, header=headers)
msg = ws.recv()
print(json.loads(msg))