Migration 0002 adds the market data tables on both engines: daily and one-minute bars, corporate actions, FX rates, the exchange calendar, calendar events, mood indicators, spread samples, data issues, source state and universe members, plus the trading rules on instruments. The data layer is format-independent so the venue clients can build on it: the instrument catalogue (rules from the venue, delisted kept), bar upserts with ON CONFLICT, the SPEC 6.4 checks with an issue register that blocks entries until a second reading, freshness by age of the last datum (trap 10), research history in .csv.gz with exact decimals, and adjusted series anchored at the decision day with level and quantity conversion across splits and dividends. Recorded API responses from OKX, the Alpaca docs and the free sources are kept byte for byte as test fixtures; the secret scan now ignores pagination cursors such as Alpaca's next_page_token. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6.7 KiB
OKX v5 WebSocket — examples
Source of [DOCS] blocks: https://my.okx.com/docs-v5/en/ (sections "WebSocket > Connect", "Subscribe", "Notification", "Connection count limit", "WS / Tickers channel", "WS / Candlesticks channel", "Error Code > WebSocket"), read on 2026-11-10. Source of [LIVE] blocks: real frames captured on 2026-11-10 from wseea.okx.com / wseeapap.okx.com (no login). Frames are copied byte-for-byte as received.
URLs
| Use | URL | Channels |
|---|---|---|
| Production public | wss://wseea.okx.com/ws/v5/public |
tickers, books*, trades, ... |
| Production business | wss://wseea.okx.com/ws/v5/business |
candle* (all candle channels) |
| Demo public | wss://wseeapap.okx.com/ws/v5/public |
as production |
| Demo business | wss://wseeapap.okx.com/ws/v5/business |
as production |
Keepalive [DOCS, "Connect"]
- The server closes the connection if no subscription is established or no data is pushed for more than 30 s (close code 4004 "No data received in 30s").
- Client rule: reset an N-second timer (N < 30) on every received message; when it fires, send the
plain text frame
ping(not JSON); expect the plain text framepongwithin N s, otherwise reconnect. - Connection limit: 3 connection requests per second per IP.
- Request limit: 480
subscribe/unsubscribe/loginrequests per connection per hour. - Total length of the
argsof one request: max 64 KB.
[LIVE] public, after a tickers subscription:
> ping
< pong
Note: pushes already in flight can arrive before the pong (observed live).
Subscribe request [DOCS]
{
"id": "1512",
"op":"subscribe",
"args":[
{
"channel":"tickers",
"instId":"BTC-USDT"
}
]
}
id is optional, client-chosen, up to 32 alphanumeric characters, echoed in the response.
Unsubscribe: same shape with "op":"unsubscribe".
Subscription confirmation [DOCS]
{
"id": "1512",
"event": "subscribe",
"arg": {
"channel": "tickers",
"instId": "BTC-USDT"
},
"connId": "accb8e21"
}
[LIVE] public, tickers BTC-EUR:
{"id":"1","event":"subscribe","arg":{"channel":"tickers","instId":"BTC-EUR"},"connId":"53efe456"}
[LIVE] business, two args in one request -> one confirmation per arg, same id:
> {"id":"3","op":"subscribe","args":[{"channel":"candle1m","instId":"BTC-EUR"},{"channel":"candle1Dutc","instId":"BTC-EUR"}]}
< {"id":"3","event":"subscribe","arg":{"channel":"candle1m","instId":"BTC-EUR"},"connId":"3e5c5e42"}
< {"id":"3","event":"subscribe","arg":{"channel":"candle1Dutc","instId":"BTC-EUR"},"connId":"3e5c5e42"}
Error response [DOCS]
{
"id": "1512",
"event": "error",
"code": "60012",
"msg": "Invalid request: {\"op\": \"subscribe\", \"argss\":[{ \"channel\" : \"tickers\", \"instId\" : \"LTC-USD-200327\"}]}",
"connId": "a4d3ae55"
}
[LIVE] subscribing candle1m on the PUBLIC url (wrong url) -> code 60018 (not 64001):
{"event":"error","msg":"Subscribe failed, wrong URL or channel:candle1m,instId:BTC-EUR doesn't exist. Please use the correct URL, channel and parameters referring to API document.","code":"60018","connId":"53efe456","id":"2"}
Main WS error codes [DOCS]: 60012 Invalid request; 60013 Invalid args; 60014 Requests too frequent; 60018 Wrong URL or {0} doesn't exist; 60019 Invalid op; 64001 channel migrated to '/business' URL; 64002 channel not supported by '/business' URL; 64008 connection will close for service upgrade; 64010 port 8443 will be retired. Close frames: 4004 No data received in 30s; 4008/4009 too many subscribed channels; 1009 message exceeds the maximum frame length.
Tickers push (channel tickers, public URL) [DOCS]
Fastest 1 update / 100 ms; only on trade or best bid/ask change.
{
"arg": {
"channel": "tickers",
"instId": "BTC-USDT"
},
"data": [
{
"instType": "SPOT",
"instId": "BTC-USDT",
"last": "9999.99",
"lastSz": "0.1",
"askPx": "9999.99",
"askSz": "11",
"bidPx": "8888.88",
"bidSz": "5",
"open24h": "9000",
"high24h": "10000",
"low24h": "8888.88",
"volCcy24h": "2222",
"vol24h": "2222",
"sodUtc0": "2222",
"sodUtc8": "2222",
"ts": "1597026383085"
}
]
}
[LIVE] BTC-EUR:
{"arg":{"channel":"tickers","instId":"BTC-EUR"},"data":[{"instType":"SPOT","instId":"BTC-EUR","last":"66148.9","lastSz":"0.00010133","askPx":"66134.7","askSz":"0.01847","bidPx":"66129.6","bidSz":"0.0193605","open24h":"66709.6","high24h":"67457","low24h":"65700","sodUtc0":"67082.7","sodUtc8":"67429.6","volCcy24h":"5581463.825401407","vol24h":"83.92407803","ts":"1794318514123"}]}
Candle push (channels candle1m, candle1Dutc, ..., BUSINESS URL) [DOCS]
Fastest push every 1 s. data is an array of arrays
[ts,o,h,l,c,vol,volCcy,volCcyQuote,confirm]; confirm "0" = in progress, "1" = closed.
Channel names include candle1s, candle1m, candle3m, candle5m, candle15m, candle30m, candle1H, candle2H,
candle4H, candle6H, candle12H, candle1D, candle2D, candle3D, candle5D, candle1W, candle1M, candle3M and the
UTC variants candle6Hutc, candle12Hutc, candle1Dutc, candle2Dutc, candle3Dutc, candle5Dutc, candle1Wutc,
candle1Mutc, candle3Mutc. Note candle1m = 1 minute, candle1M = 1 month.
{
"arg": {
"channel": "candle1D",
"instId": "BTC-USDT"
},
"data": [
[
"1597026383085",
"8533.02",
"8553.74",
"8527.17",
"8548.26",
"45247",
"529.5858061",
"5529.5858061",
"0"
]
]
}
[LIVE] BTC-EUR candle1m:
{"arg":{"channel":"candle1m","instId":"BTC-EUR"},"data":[["1794318480000","66104.2","66148.9","66104.2","66132.7","0.01956494","1293.950829541","1293.950829541","0"]]}
Notices [DOCS + LIVE]
[DOCS] service upgrade, sent 60 s before disconnect:
{
"event": "notice",
"code": "64008",
"msg": "The connection will soon be closed for a service upgrade. Please reconnect.",
"connId": "a4d3ae55"
}
[LIVE] connecting to port 8443 (both wss://wseea.okx.com:8443/ws/v5/public and
wss://wseeapap.okx.com:8443/ws/v5/public still accepted the connection on 2026-11-10 and sent this
once after the handshake; the connection stays open):
{"event":"notice","msg":"WebSocket port 8443 will be retired soon. Please migrate to port 443.","code":"64010","connId":"6a3d66ba"}
Connection count limit [DOCS]
30 connections per channel per sub-account, but ONLY for private channels (orders, account, positions,
balance_and_position, liquidation-warning, account-greeks). Events channel-conn-count and
channel-conn-count-error. No per-connection limit on public channels is documented beyond the
480 requests/hour, 64 KB args and 3 connections/s per IP rules above.