Skip to content

Order.type is a dead field; inconsistent bool query-param serialization #91

Description

@TexasCoding

From Wave 5 architecture audit. Two small polish items in one issue.

F-N-03 — `Order.type` dead field (severity: medium)

`kalshi/models/orders.py:47` — `Order.type: str | None = None`. Leftover from the pre-v0.8.0 `CreateOrderRequest.type` field that v0.8.0 removed because it wasn't in the OpenAPI spec. The response `Order` model still carries it, which:

  • Re-exposes the removed concept.
  • Shadows the Python `type` builtin in instances.
  • Lets the spec-drift contract test pass only because `Order` has `extra="allow"`.

Investigation needed: does the Kalshi demo actually return a `type` field on `/portfolio/orders` responses? If not, remove the field. If it does return one, either add it to the OpenAPI spec drift exclusions explicitly with a documented reason, or rely on `extra="allow"` so callers reach it via `order.model_extra`.

F-N-08 — Inconsistent bool query-param serialization (severity: medium)

`kalshi/resources/_base.py:22-32` defines `_bool_param(value)` specifically to preserve the explicit-False case — the docstring warns against inline ternaries. `markets.py` and `live_data.py` use it correctly. `events.py` and `series.py` instead use inline `"true" if include_volume else None` for every bool param, which is exactly the pattern the helper docstring warns against:

  • `events.py:29,30,49,139,233` — `with_nested_markets="true" if with_nested_markets else None`
  • `series.py:30,31,43,101,191` — `include_product_metadata="true" if include_product_metadata else None`

For at least `include_volume` (which affects response shape and is volume-load-bearing) callers cannot turn it off explicitly. Replace all inline ternaries with `_bool_param(...)`. Mechanical and safe; only behavioral difference is `False` now becomes `"false"` instead of being dropped — which is the documented intent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    polishCode-quality and DX improvements; non-functional

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions