Skip to content

WS: expose ws_ping_interval / ws_close_timeout via KalshiConfig (currently hardcoded) #208

Closed

Description

@TexasCoding

Summary

ConnectionManager.__init__ accepts heartbeat_timeout (forwarded to ping_timeout), but ping_interval=20 and close_timeout=5.0 are hardcoded literals duplicated across connect and reconnect. There is no KalshiConfig.ws_ping_interval or KalshiConfig.ws_close_timeout.

  • Mobile / high-RTT consumers cannot lengthen the interval to avoid spurious disconnects.
  • Latency-sensitive consumers cannot shorten it to detect dead peers faster.
  • The duplication invites drift if one literal is updated and the other forgotten.

Location

kalshi/ws/connection.py:122-127, 178-182

Evidence

# kalshi/ws/connection.py:122-127 and 178-182 — same three literals repeated
self._ws = await connect(
    self._config.ws_base_url,
    additional_headers=headers,
    ping_interval=20,                       # hardcoded
    ping_timeout=self._heartbeat_timeout,   # configurable (good)
    close_timeout=5.0,                       # hardcoded
)

Recommended fix

  1. Add to KalshiConfig:

    ws_ping_interval: float = 20.0
    ws_close_timeout: float = 5.0
  2. Reference them in both connect paths in ConnectionManager.

  3. Extract a single private helper _open_socket() to deduplicate the await connect(...) call site (eliminates the drift risk).

Tests:

  • test_ws_ping_interval_from_config_passed_through
  • test_ws_close_timeout_from_config_passed_through

Severity & category

medium / dx, ws

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestwsWebSocket-related

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions