Via WebSocket long connection , receive real-time A-share, Hong Kong stock, and ETF market data, updated every 3~5 seconds.
Architecture
Receiver Node (HTTP API) → scripts/subscribe_client.py → ws://localhost:8765 → 客户端
Environment Preparation
pip install requests websockets
export STOCK_RT_NODE_URL="http://your-node:9100"
export STOCK_RT_TOKEN="your-token" # 可选,有鉴权时设置
Quick Start
One-time Query (Verify Connectivity)
python3 scripts/subscribe_client.py --symbols 00700.HK 600519.SH --once
Start WebSocket Push Service
# 基础订阅
python3 scripts/subscribe_client.py --symbols 00700.HK 09988.HK 600519.SH
# 指定节点和端口
python3 scripts/subscribe_client.py --node-url http://your-node:9100 --ws-port 8765 --symbols 00700.HK
# 涨跌幅告警(±2% 触发)
python3 scripts/subscribe_client.py --symbols 00700.HK --alert-pct 2.0
# 输出到文件
python3 scripts/subscribe_client.py --symbols 00700.HK --output ticks.jsonl
Start Programmatically
from scripts.subscribe_client import StockWSServer
server = StockWSServer(
node_url="http://your-node:9100",
symbols=["00700.HK", "09988.HK"],
poll_interval=3.0,
)
server.add_callback(lambda sym, tick: print(f"{tick.name}: {tick.close}"))
server.run(port=8765)
AI Agent Integration
from scripts.ai_agent_integration import StockDataAgent
agent = StockDataAgent()
agent.install() # 检查依赖、验证节点连通性
# 完整工作流(订阅 + 告警监控 60 秒)
import asyncio
asyncio.run(agent.complete_workflow(['00700.HK', '600519.SH'], duration=60))
Alert Strategies
For alert rule configuration, see references/strategy_config.json, built-in strategies:
limit_up_down: Limit up/limit down monitoringbig_move: Significant fluctuations (≥ ±5%)vol_spike: Abnormal trading volume (≥ 3 times the average volume of the past 5 days)price_breakout: Price breaks above the 20-day high
Reference Documentation
- references/api.md: WebSocket message format, data field descriptions, client connection examples (Python/JS/wscat), dynamic subscription management commands, troubleshooting guide
- references/strategy_config.json: Complete alert strategy configuration