stock-rt-subscribe

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Real-time Stock Data Subscription

实时股票数据订阅

Subscribe to live stock market data with 1.5-second K-line updates via WebSocket.
通过WebSocket订阅实时股票市场数据,K线更新频率约1.5秒。

Prerequisites

前提条件

This skill requires:
  1. STOCK_RT_TOKEN environment variable — a JWT token from a real-time subscription plan
  2. STOCK_RT_WS_URL environment variable — the WebSocket endpoint URL (provided at purchase time)
使用该功能需要:
  1. STOCK_RT_TOKEN 环境变量——来自实时订阅套餐的JWT令牌
  2. STOCK_RT_WS_URL 环境变量——WebSocket端点URL(购买时提供)

Setup Check

配置检查

bash
undefined
bash
undefined

Check if token exists

检查令牌是否存在

echo ${STOCK_RT_TOKEN:+Token is set}${STOCK_RT_TOKEN:-ERROR: STOCK_RT_TOKEN not set} echo ${STOCK_RT_WS_URL:+WS URL is set}${STOCK_RT_WS_URL:-ERROR: STOCK_RT_WS_URL not set}

If not set:

1. Visit the management platform (nps_enhanced web panel)
2. Navigate to "Real-time Stock Subscription" page
3. Choose a plan based on how many symbols you need to track:
   - Pack 5: 5 symbols, 10 CNY/month
   - Pack 15: 15 symbols, 20 CNY/month
   - Pack 50: 50 symbols, 50 CNY/month
4. Select a node that supports real-time stock data
5. Complete purchase and copy the token + WebSocket URL
6. Set environment variables:
   ```bash
   export STOCK_RT_TOKEN="eyJ..."
   export STOCK_RT_WS_URL="wss://your-node:8443/ws/stock"
echo ${STOCK_RT_TOKEN:+Token is set}${STOCK_RT_TOKEN:-ERROR: STOCK_RT_TOKEN not set} echo ${STOCK_RT_WS_URL:+WS URL is set}${STOCK_RT_WS_URL:-ERROR: STOCK_RT_WS_URL not set}

如果未设置:

1. 访问管理平台(nps_enhanced 网页面板)
2. 导航至“实时股票订阅”页面
3. 根据需要追踪的标的数量选择套餐:
   - 套餐5:5个标的,10元/月
   - 套餐15:15个标的,20元/月
   - 套餐50:50个标的,50元/月
4. 选择支持实时股票数据的节点
5. 完成购买并复制令牌和WebSocket URL
6. 设置环境变量:
   ```bash
   export STOCK_RT_TOKEN="eyJ..."
   export STOCK_RT_WS_URL="wss://your-node:8443/ws/stock"

Subscription Plans

订阅套餐

PlanSymbolsMarketsPrice
Pack 5 (Entry)5A-shares + HK10 CNY/month
Pack 15 (Standard)15A-shares + HK20 CNY/month
Pack 50 (Pro)50A-shares + HK50 CNY/month
All plans include ETF data. Symbol quota stacks when renewing.
套餐标的数量市场价格
套餐5(入门版)5A股 + 港股10元/月
套餐15(标准版)15A股 + 港股20元/月
套餐50(专业版)50A股 + 港股50元/月
所有套餐均包含ETF数据。续订时标的配额可叠加。

WebSocket Connection

WebSocket连接

Connect to the WebSocket endpoint with your token:
WebSocket URL: ${STOCK_RT_WS_URL}
Authorization: Bearer ${STOCK_RT_TOKEN}
使用令牌连接至WebSocket端点:
WebSocket URL: ${STOCK_RT_WS_URL}
Authorization: Bearer ${STOCK_RT_TOKEN}

Message Protocol

消息协议

Subscribe to symbols:
json
{
  "action": "subscribe",
  "symbols": ["000001.SZ", "600519.SH", "00700.HK"]
}
Unsubscribe:
json
{
  "action": "unsubscribe",
  "symbols": ["000001.SZ"]
}
Real-time data format (pushed every ~1.5s):
json
{
  "type": "kline",
  "symbol": "000001.SZ",
  "data": {
    "open": 10.50,
    "high": 10.55,
    "low": 10.48,
    "close": 10.52,
    "volume": 123456,
    "amount": 1298765.00,
    "timestamp": "2026-03-08T14:30:01.500Z"
  }
}
订阅标的:
json
{
  "action": "subscribe",
  "symbols": ["000001.SZ", "600519.SH", "00700.HK"]
}
取消订阅:
json
{
  "action": "unsubscribe",
  "symbols": ["000001.SZ"]
}
实时数据格式(约每1.5秒推送一次):
json
{
  "type": "kline",
  "symbol": "000001.SZ",
  "data": {
    "open": 10.50,
    "high": 10.55,
    "low": 10.48,
    "close": 10.52,
    "volume": 123456,
    "amount": 1298765.00,
    "timestamp": "2026-03-08T14:30:01.500Z"
  }
}

Data Characteristics

数据特性

  • Update Frequency: ~1.5 seconds during market hours
  • Markets: CN (A-shares), HK (Hong Kong)
  • Data Retention: Real-time stream via Redis (72-hour window), minute-level data persisted to ClickHouse
  • Latency: Depends on network and node location
  • 更新频率:交易时段约1.5秒一次
  • 覆盖市场:中国内地(A股)、中国香港(港股)
  • 数据留存:通过Redis实现实时流(72小时窗口),分钟级数据持久化至ClickHouse
  • 延迟:取决于网络和节点位置

Token Scope

令牌范围

The JWT token contains:
  • markets: Which markets you can access (e.g.,
    ["CN", "HK"]
    )
  • levels: Data levels (e.g.,
    ["L1"]
    )
  • quota.max_subs: Maximum concurrent symbol subscriptions
JWT令牌包含以下信息:
  • markets:可访问的市场(例如
    ["CN", "HK"]
  • levels:数据级别(例如
    ["L1"]
  • quota.max_subs:最大并发标的订阅数

Troubleshooting

故障排除

  • WebSocket connection refused: Check that the node supports real-time data and the WS URL is correct
  • 401 on connect: Token expired or invalid. Check subscription status on the management platform
  • No data after subscribe: Verify the market is currently open; no data is pushed during closed hours
  • Max subscriptions reached: You've hit your symbol quota. Upgrade your plan or unsubscribe from some symbols
  • WebSocket连接被拒绝:检查节点是否支持实时数据,以及WS URL是否正确
  • 连接时返回401:令牌过期或无效。请在管理平台检查订阅状态
  • 订阅后无数据:验证当前市场是否开市;休市期间不会推送数据
  • 达到最大订阅数:已触及标的配额上限。升级套餐或取消部分标的订阅