WebSocket connection¶
Base¶
WebSocket hosts are distinct from REST API hosts (see Base URLs):
| Environment | Base |
|---|---|
| Production | wss://ws.pcrypto.com |
Examples below use <websocket-host> as a placeholder — substitute the host for your environment from Base URLs.
Public market data¶
| Path | Behaviour |
|---|---|
/openapi/quote/ws/v1/<streamName> |
Single stream — already bound on connect; no SUBSCRIBE needed. Use combined mode if you need to add/remove streams dynamically. |
/openapi/quote/stream?streams=a/b/c |
Combined mode; each message is wrapped as { "stream", "data" } |
Examples:
wss://<websocket-host>/openapi/quote/ws/v1/btcusdt@aggTrade
wss://<websocket-host>/openapi/quote/stream?streams=btcusdt@aggTrade/btcusdt@depth20
Combined-mode payload example:
{
"stream": "btcusdt@aggTrade",
"data": {
"e": "aggTrade",
"E": 1672515782136,
"s": "BTCUSDT",
"a": 5933014,
"p": "0.001",
"q": "100",
"f": 100,
"l": 105,
"T": 1672515782136,
"m": true
}
}
data matches the single-stream payload for that channel.
Private user data¶
Then authenticate with a post-handshake authentication message (put the listenKey in the message body, not the URL):
Create / keepalive / close listenKey via REST (/openapi/v1/userDataStream, API key only). Event schemas and enums: Private user data.
Unsupported paths¶
Do not use these paths:
| Path | Notes |
|---|---|
/ws, /ws/spot |
Legacy aliases — use /openapi/quote/… and /openapi/ws/… instead |
Heartbeat¶
| Direction | Mechanism |
|---|---|
| Server → client | WebSocket Ping every 20s; respond with Pong within 120s or disconnect |
| Client → server | JSON {"ping": <epochMs>} → {"pong": <epochMs>} |
Prefer answering the WebSocket Ping frame. JSON ping/pong is a compatibility fallback.
Limits¶
| Limit | Value |
|---|---|
| Client messages | 25 / s |
| Idle public connection | Public connections with zero subscribed streams disconnect after 60s. Private listenKey sessions do not require SUBSCRIBE. |
Subscribe / unsubscribe¶
Success reply shape: { "result": null, "id": <n> } (or subscription list for LIST).
Legacy op form is also accepted; prefer method / params:
| Legacy | Preferred |
|---|---|
"op": "subscribe" |
"method": "SUBSCRIBE" |
"args": [...] |
"params": [...] |