Skip to content

orders.create type overload still permits omitting required action/count #350

Closed

Description

@TexasCoding

Problem

v2.5 removed the silent 1-contract / action="buy" defaults at runtime (a TypeError now fires when any of ticker / side / count / action is missing). The public overload still advertises action and count as optional kwargs (None = ...), so a strict type-checking user can write client.orders.create(ticker="T", side="yes", yes_price="0.50") and mypy accepts it — the call then raises TypeError before any HTTP request is made.

Not a wire-corruption bug anymore, but it leaves the SDK's static contract inconsistent precisely on the money-risk branch v2.5 was meant to harden.

Evidence

  • kalshi/resources/orders.py:330-345 — overload still optional:
@overload
def create(
    self,
    *,
    ticker: str,
    side: SideLiteral,
    action: ActionLiteral | None = ...,
    count: int | None = ...,
    yes_price: float | str | int | None = ...,
    no_price: float | str | int | None = ...,
    ...
) -> Order: ...
  • kalshi/resources/orders.py:104-112 — runtime guard already strict:
if request is None:
    if ticker is None or side is None or count is None or action is None:
        raise TypeError(
            "create() requires `ticker`, `side`, `count`, and `action` "
            ...
        )

Suggested fix

Change the kwarg-form overload (sync OrdersResource.create and async AsyncOrdersResource.create) so action: ActionLiteral and count: int are required (no None, no default):

@overload
def create(
    self,
    *,
    ticker: str,
    side: SideLiteral,
    action: ActionLiteral,
    count: int,
    yes_price: float | str | int | None = ...,
    ...
) -> Order: ...

Keep the implementation signature's None defaults for overload dispatch and runtime error quality. Add a mypy-level regression test (e.g. via tests/test_type_overloads.py if present, or a # type: ignore[call-overload] assertion in a typed test fixture) confirming the trimmed overload rejects the missing-arg shape.

Source

Round-3 independent audit (reviewer: codex).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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