Viewing: Errors

Real-time WebSocket - Errors

Handle WebSocket errors using a consistent error message format. Use the connection close code to identify the error category, and the latest error.code and error.details to determine the appropriate action.

WebSocket Error Codes

WS_INTERNAL_ERROR4000

An internal connection failure interrupted setup.

Action: Retry with capped exponential backoff and jitter.

WS_AUTH_OR_ACCESS4401 / 4403

MARKET_DATA_ENTITLEMENT_*

Account access or entitlement issue blocks streaming access.

Action: 4401 means fix API key auth, 4403 means fix account/plan entitlement state. Do not auto-reconnect.

WS_RATE_LIMIT4429

DEPTH_WS_*_LIMIT / *_RATE_LIMITED

Connection, subscription, or action throttles were exceeded.

Action: Retry with backoff and jitter, and honor retry_after_seconds from the latest error details when it is present.

WS_INVALID_REQUEST

INVALID_JSON / UNKNOWN_ACTION / SYMBOL_REQUIRED and lowercase variants

Malformed payload or unsupported action.

Action: Codes are channel-specific and case-sensitive. Fix the payload and retry the action; the socket normally remains open.

protocol_ping_timeout1006

The server closed the TCP connection because no protocol pong and no data frame arrived within 30 seconds of its protocol ping. There is no close frame.

SAHMK sends that protocol ping about 20 seconds after the last data frame from your client. A client that answers neither is closed about 50 seconds after it goes quiet.

Action: Answer protocol pings. Browsers and Python's websockets library do this automatically. The JSON ping in the client actions is a data frame and also resets the timer. Reconnect with capped exponential backoff and jitter, then subscribe again.

Multi-connection guardrails

  • Open sockets with a 200-400ms stagger instead of starting all at once.
  • Queue reconnect attempts globally per API key.
  • Avoid synchronized reconnect storms around market open.

Off-hours connections

You may keep WebSocket connections open outside market hours. SAHMK does not intentionally disconnect clients at market close. Continue sending a ping every 30 seconds, reconnect with capped exponential backoff and jitter when necessary, and restore subscriptions after every reconnect. Market events may be absent while the market is inactive.

Error Envelope

json
{
  "type": "error",
  "code": "ERROR_CODE",
  "message": "Human-readable message",
  "details": {}
}

Last updated on