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/public24h tickers, candles, trades, order books, index prices and CFD quotes. No login needed.
Private endpoint
wss://api.kdc.exchange/open/v1/ws/privateReal-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.
| Frame | Shape | Description |
|---|---|---|
| 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 code | Reason | What to do |
|---|---|---|
4000 | No frame received for 60 seconds | Send heartbeats on time |
4001 | Not 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 |
4008 | Reading too slowly; the server's outgoing queue is full | Read messages promptly; reconcile after reconnecting |
1009 | Sent frame larger than 64 KB | Split it and resend |
1012 | Service restart | Reconnect immediately |