You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
WS message envelope type field is bare str with a default — should be Literal #353
Every WS message envelope class declares type: str = "<channel>" with no Literal narrowing. Concrete consequences:
OrderbookSnapshotMessage(sid=1, seq=1, msg=..., type="fill") constructs successfully — there is no construction-time signal that the envelope's type disagrees with its class.
A future refactor of the dispatcher that routes by model identity rather than the raw msg["type"] string would let a mistyped envelope payload slip into the wrong handler with no error.
The asyncapi spec defines these envelopes as closed enums on the type field. Pydantic v2 supports discriminated unions via Discriminator("type"); narrowing each envelope's type to its Literal[...] value unlocks that and gives static analysis exhaustiveness checks for free. No wire-format change.
Apply across orderbook_delta.py, ticker.py, fill.py, user_orders.py, market_lifecycle.py, and any other envelope under kalshi/ws/models/ (trade, order_group, multivariate, market_positions, communications). The default-value form keeps construction ergonomics. Once narrowed, the dispatcher's union can be expressed with pydantic.Discriminator("type") for first-class pydantic dispatch and exhaustive mypy matching.
Activity
fix(ws-models): OrderbookDeltaPayload.ts AwareDatetime + envelope typ…