Skip to main content
Connect to wss://api.tickdb.ai/v1/realtime and pass your API key in the api_key query parameter. Do not put long-lived API keys in public frontend code or logs.

Connection Management

  • Compression: Full-market subscriptions must negotiate permessage-deflate during the handshake. Enable it explicitly in a Node.js client and check the negotiated extension after connecting. Browsers usually offer it automatically. Accept-Encoding does not control WebSocket compression.
  • Heartbeat: The client automatically replies to WebSocket protocol-level Pings from the server, so high-frequency application messages are unnecessary. The example sends {"cmd":"ping"} every 60 seconds as an additional client-side health check and closes a stale connection if no pong arrives within 20 seconds.
  • Reconnection: Use the fixed stages below, without random delay. Stay at the last stage until reconnecting succeeds. A successful connection resets the counter, so the next disconnection starts from the first stage again.
  • Resubscription: Send subscriptions again after every reconnect. A full-market subscription receives another initial snapshot. Fix authentication, permission, or compression errors instead of retrying indefinitely.
  • Message format: Regular channels generally send single messages. Full-market updates arrive in arrays of up to 500 ticker messages.
In RECONNECT_STAGES, each entry pairs a delay with the number of attempts at that delay. Add or adjust stages as needed; Infinity in the final entry keeps retrying at that interval.

Node.js Example

Install ws with npm install ws. Set TICKDB_API_KEY before running the code. Optionally set TICKDB_UNIVERSE to CN_Stock, HK_Stock, or US_Stock to subscribe to all symbols in that market. The example’s 60-second application heartbeat and 20-second timeout are adjustable.
See the Real-Time Quotes, Orderbook, Tick-by-Tick Trades, and Ping pages for channel-specific commands and response fields. See the A-share, Hong Kong stock, and US stock pages for full-market compression and message formats.