Fix WebSocket ts parsing for ISO 8601 timestamps (closes #18)#19
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tsfield from int ms to ISO 8601 strings (e.g.'2026-04-22T18:31:59.043421Z') in April 2026, breaking every WS connection with aValueErroron the first message and triggering an infinite reconnect storm._parse_tshelper that accepts both legacy int-ms and the new ISO 8601 format, used by bothFeed._dispatchandAsyncFeed.__aiter__. Same helper is wired into the Pydantic message models via aTsFieldannotation so typed messages keep validating instead of falling back to raw dicts.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).reconnect_count == 0, payloads arrive as typedTickerMessage(not raw dict).🤖 Generated with Claude Code