Skip to content

AmendOrderRequest.side/.action still bare str after v2.5 narrowed CreateOrderRequest #312

Closed

Description

@TexasCoding

Problem

v2.5 narrowed CreateOrderRequest.side / .action (and related fixed-enum fields) to their Literal aliases so a typo like side="yess" fails at construction. AmendOrderRequest was left at bare str, even though amend has the same money-routing surface (price/count change on an open order) and the same enum constraints in the spec.

A caller building an amend body directly — AmendOrderRequest(ticker="X", side="yess", action="buy", count=Decimal(1)) — constructs without error, the SDK signs the request, the server rejects with 400. Same fail-fast argument that drove v2.5; same fix.

Evidence

  • kalshi/models/orders.py:17-21 — Literal aliases exist:
SideLiteral = Literal["yes", "no"]
ActionLiteral = Literal["buy", "sell"]
  • kalshi/models/orders.py:173-175 — CreateOrderRequest uses the narrowed types:
ticker: str
side: SideLiteral
action: ActionLiteral
  • kalshi/models/orders.py:252-254 — AmendOrderRequest still bare str:
ticker: str
side: str
action: str
  • kalshi/models/orders.py:14-16 — the stale top-of-file comment ("Pydantic request models leave these fields as str to remain tolerant of spec drift") now applies only to AmendOrderRequest by accident; CreateOrderRequest and CreateOrderV2Request (lines 471-477) have already been narrowed.

  • CHANGELOG.md:270-272 — v2.5 closure: "V1 CreateOrderRequest enum-style fields narrowed to Literal[...] (Polish bundle: model small items (AwareDatetime in WS, V1 Literal, default=None, timestamp typing, Decimal NaN) #270). Closes the V1/V2 strictness gap." AmendOrderRequest is not mentioned.

Suggested fix

In kalshi/models/orders.py, change side: str → side: SideLiteral and action: str → action: ActionLiteral on AmendOrderRequest. Update or remove the stale module-level comment at lines 13-16 since both V1 and V2 create paths are already narrowed. Add a regression test mirroring the v2.5 CreateOrderRequest test asserting AmendOrderRequest(ticker="X", side="yess", action="buy", count=Decimal(1)) raises ValidationError on side.

Source

Round-3 independent audit (reviewer: models_contracts+resources_api).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpolishCode-quality and DX improvements; non-functionalspec-driftUpstream OpenAPI/AsyncAPI spec changed since last sync

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions