Skip to content

Fix WebSocket ts parsing for ISO 8601 timestamps (closes #18)#19

Merged
arshka merged 2 commits into
mainfrom
fix/ws-ts-iso8601
May 2, 2026
Merged

Fix WebSocket ts parsing for ISO 8601 timestamps (closes #18)#19
arshka merged 2 commits into
mainfrom
fix/ws-ts-iso8601

Conversation

@arshka
Copy link
Copy Markdown
Owner

@arshka arshka commented May 2, 2026

Summary

  • Kalshi switched the WebSocket ts field from int ms to ISO 8601 strings (e.g. '2026-04-22T18:31:59.043421Z') in April 2026, breaking every WS connection with a ValueError on the first message and triggering an infinite reconnect storm.
  • Adds a _parse_ts helper that accepts both legacy int-ms and the new ISO 8601 format, used by both Feed._dispatch and AsyncFeed.__aiter__. Same helper is wired into the Pydantic message models via a TsField annotation so typed messages keep validating instead of falling back to raw dicts.
  • Bumps version to 1.0.5.

Fixes #18.

Test plan

  • pytest tests/ — 308 passed (added 10 new tests covering int passthrough, ISO with/without microseconds, numeric-string, garbage rejection, model-level coercion, and the regression scenario from the issue).
  • Reproduced issue scenario: 100 ISO-timestamped messages dispatched, reconnect_count == 0, payloads arrive as typed TickerMessage (not raw dict).

🤖 Generated with Claude Code

arshka and others added 2 commits May 2, 2026 00:12
Kalshi's WebSocket API switched the `ts` field from int milliseconds to
ISO 8601 strings (e.g. '2026-04-22T18:31:59.043421Z') in April 2026.
`Feed._dispatch` and `AsyncFeed.__aiter__` called `int(ts)` directly,
raising ValueError on every message and triggering a reconnect storm.

Adds `_parse_ts` helper that accepts both int ms and ISO 8601, plus a
`TsField` annotation applied to every model with a `ts` field so typed
messages still validate cleanly under the new server format.

Bumps version to 1.0.5.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Drop bool/float branches and numeric-string handling that Kalshi never
sends. Drop redundant ISO-without-microseconds, unparseable, and
non-Ticker-model tests covering identical code paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@arshka arshka merged commit 705fd78 into main May 2, 2026
5 of 6 checks passed
@arshka arshka deleted the fix/ws-ts-iso8601 branch May 2, 2026 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ValueError: invalid literal for int() with base 10 — Kalshi changed ts field to ISO 8601 string

1 participant