Construction
The WebSocket is created with the same exchange ID and config asExchange.new. In Python and TypeScript, call exchange.websocket() to
reuse credentials.
Subscription target by exchange
subscribe(market_id) takes a string whose meaning depends on the exchange:
| Exchange | What to pass |
|---|---|
| Kalshi | Market ticker (e.g. KXBTC-25MAR14-T20000) |
| Polymarket | A CLOB token ID (e.g. Market.token_id_yes or token_id_no) |
subscribe_pair(yes_token, no_token) for
binary markets — both sides get full book updates, and price_change events
on either side are dispatched correctly.
Outcome labels (Polymarket)
Activity events (Trade, Fill) include an outcome label ("Yes" / "No")
when token IDs are registered. Either subscribe via subscribe_pair, or
call:
Reconnect & keepalive
Tunable constants inengine/core/src/websocket/traits.rs:
| Constant | Value | Purpose |
|---|---|---|
WS_PING_INTERVAL | 20s | Keepalive ping cadence |
WS_RECONNECT_BASE_DELAY | 3s | Initial reconnect backoff |
WS_RECONNECT_MAX_DELAY | 60s | Cap on backoff |
WS_MAX_RECONNECT_ATTEMPTS | 10 | Before giving up |
WS_STALL_TIMEOUT | 90s | Force reconnect if no message received |
WS_STALL_CHECK_INTERVAL | 10s | How often the stall watchdog ticks |
SessionEvent::Reconnected { gap_ms } plus a
Snapshot for every previously subscribed market.