KDC Open APIv1/WebSocket overview
DEVELOPER GUIDE

WebSocket overview

Receive market data and account changes in real time over a persistent connection, and trade directly on it. Market data needs no login; the private connection logs in with an API key signature.

Market data endpoint
wss://api.kdc.exchange/open/v1/ws/public

24h tickers, candles, trades, order books, index prices and CFD quotes. No login needed.

Private endpoint
wss://api.kdc.exchange/open/v1/ws/private

Real-time orders, fills, positions, balances and futures account updates, plus order placement, cancellation, batches and calls to any private endpoint. Requires a signed login.

Frame format

All frames are UTF-8 JSON text frames. Amounts, quantities and 64-bit IDs are strings, as in REST. Ignore fields or channels you don't recognize; more will be added.

FrameShapeDescription
Request{"op": "sub", "id": "1", "args": [...]}You choose the id; it is echoed back in the reply so you can match requests. Optional.
Reply{"op": "sub", "id": "1", "code": 0, "msg": "", "data": {...}}code, msg and params are the same as in REST; code 0 means success.
Push{"ch": "ticker:BTCUSDT", "ts": 1795400000123, "seq": 7, "data": {...}}ch is the channel name; seq is a per-connection counter for troubleshooting only and restarts at 1 after reconnecting.

Heartbeat & reconnection

  • Send a frame with op ping every 20 seconds; the server replies with pong. Protocol-level ping frames also count. The server closes the connection after 60 seconds without any frame.
  • After a disconnect, retry with backoff of 1, 2, 4, 8, 16 and 30 seconds plus a little random jitter. Log in and subscribe again after reconnecting.
  • Pushes missed while disconnected are not replayed: reconcile private data with REST (open orders, positions, balances) and backfill trades and candles with REST. Order books resend a full snapshot when you resubscribe.

Close codes

Close codeReasonWhat to do
4000No frame received for 60 secondsSend heartbeats on time
4001Not logged in within 30 seconds of connecting, or the key was disabled, deleted or expired, the IP is no longer allowed, or the account was frozen (the close reason is the error key)Check the key, then reconnect
4008Reading too slowly; the server's outgoing queue is fullRead messages promptly; reconcile after reconnecting
1009Sent frame larger than 64 KBSplit it and resend
1012Service restartReconnect immediately