Skip to content

Fix trade websocket payload types - #328

Open
koriyoshi2041 wants to merge 1 commit into
hyperliquid-dex:masterfrom
koriyoshi2041:fix/trade-wire-types
Open

koriyoshi2041 wants to merge 1 commit into
hyperliquid-dex:masterfrom
koriyoshi2041:fix/trade-wire-types

Conversation

@koriyoshi2041

@koriyoshi2041 koriyoshi2041 commented Oct 9, 2026 •

Copy link
Copy Markdown

Closes #327.

The live trades websocket payload represents sz as a string, includes an integer tid, and includes users as a two-element JSON array. This updates the Python Trade TypedDict to match the values produced by Python's JSON decoder:

  • sz: str
  • tid: int
  • users: List[str]

The official Rust SDK models the same wire fields as String, u64, and (String, String). The Python annotation intentionally uses List[str] rather than copying the Rust tuple because json.loads preserves the wire array as a Python list.

Validation:

  • Live public BTC trades websocket payload inspection
  • uvx mypy hyperliquid/utils/types.py
  • uvx black --check hyperliquid/utils/types.py
  • python -m compileall -q hyperliquid/utils/types.py
  • git diff --check

@koriyoshi2041

Copy link
Copy Markdown
Author

I rechecked the public trades websocket against the live API before treating the Rust model as the final Python contract.

Observed payload shape for BTC:

keys: coin, hash, px, side, sz, tid, time, users
sz: str
tid: int
users: list (length 2)

Because Python's JSON decoder preserves the wire array as a list, I updated users from Tuple[str, str] to List[str] in 2622e5d. This keeps the Python TypedDict aligned with the actual decoded value rather than copying Rust's tuple representation across languages.

Revalidated with mypy, Black, compileall, and git diff --check.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Trade TypedDict does not match live trades payload

1 participant