Skip to content

Magic numbers: WebSocket reconnect intervals #225

@realfishsam

Description

@realfishsam

Category

WebSocket Reconnect Intervals

Locations

  • core/src/exchanges/kalshi/websocket.ts:140this.config.reconnectIntervalMs || 5000
  • core/src/exchanges/gemini-titan/websocket.ts:127this.config.reconnectIntervalMs ?? 5000
  • core/src/exchanges/opinion/websocket.ts:125this.config.reconnectIntervalMs ?? 5000
  • core/src/feeds/binance/binance-feed.ts:35config.reconnectIntervalMs ?? BINANCE_RELAY_DEFAULTS.reconnectIntervalMs (resolves to 5000 via types.ts:44)
  • core/src/feeds/chainlink/chainlink-feed.ts:57config.reconnectIntervalMs ?? CHAINLINK_DEFAULTS.reconnectIntervalMs (resolves to 5000 via types.ts:47)
  • core/src/exchanges/limitless/websocket.ts:67config.reconnectDelay ?? config.reconnectIntervalMs ?? 10001000 ms

Inconsistencies

Every exchange defaults to 5000 ms except Limitless which defaults to 1000 ms — 5× faster reconnects. There is no documentation explaining why Limitless warrants a faster reconnect cadence, and the field name also differs (reconnectDelay vs reconnectIntervalMs).

Additionally, kalshi/websocket.ts uses || (falsy check) while gemini-titan and opinion use ?? (nullish check) — a 0 value (disable reconnect) would be swallowed by the Kalshi fallback but correctly passed through by the others.

Risk

  • Limitless will reconnect 5× more aggressively than other venues after a disconnect, potentially causing unintended reconnect storms or hitting server connection limits.
  • The Kalshi || vs ?? inconsistency means reconnectIntervalMs: 0 (disable reconnect) silently becomes 5000 on Kalshi but works correctly on other exchanges.

Suggested Fix

Define a shared default in core/src/utils/ws-defaults.ts:

export const DEFAULT_RECONNECT_INTERVAL_MS = 5000;

Standardize all fallbacks to ?? (nullish). Determine and document whether Limitless's 1000 is intentional; if so, name it LIMITLESS_RECONNECT_INTERVAL_MS = 1000 in its config and add a comment explaining why it differs.


Found by automated magic numbers audit

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions