Skip to content

Fix Hyperliquid PyO3 order book depth subscriptions#4381

Merged
cjdsellers merged 1 commit into
nautechsystems:developfrom
graceyangfan:codex/hyperliquid-depth10-fix
Jul 4, 2026
Merged

Fix Hyperliquid PyO3 order book depth subscriptions#4381
cjdsellers merged 1 commit into
nautechsystems:developfrom
graceyangfan:codex/hyperliquid-depth10-fix

Conversation

@graceyangfan

Copy link
Copy Markdown
Contributor

Summary

This PR fixes the Hyperliquid Python/PyO3 order book depth path so live strategies can receive venue level order counts (n) through OrderBookDepth10.bid_counts / ask_counts.

Before this change:

  • Hyperliquid Rust parsing already preserved n
  • Hyperliquid live Python client could subscribe to order book deltas
  • Hyperliquid live Python client could not correctly subscribe to order book depth
  • PyO3 strategies therefore could not access n

After this change:

  • Hyperliquid subscribe_order_book_depth(...) works in the Python live client
  • the PyO3 websocket binding routes snapshot subscriptions to the real depth10 runtime path
  • live strategies receive OrderBookDepth10 with populated bid_counts / ask_counts

What changed

  • Implemented Hyperliquid _subscribe_order_book_depth(...) and _unsubscribe_order_book_depth(...) in the Python live data client.
  • Changed Hyperliquid PyO3 subscribe_book_snapshots(...) to call subscribe_book_depth10(...) instead of reusing subscribe_book(...).
  • Added PyO3 unsubscribe_book_snapshots(...) and synced both .pyi surfaces.
  • Added Hyperliquid integration regression coverage for depth subscribe / unsubscribe.

Why this approach

This keeps the fix adapter-local and consistent with existing Nautilus Trader design:

  • no generic model changes
  • no attempt to stuff Hyperliquid n into deltas
  • preserve venue-specific level counts in the existing OrderBookDepth10.bid_counts / ask_counts surface

Reviewer notes

The important contract is:

  1. Hyperliquid l2Book already carries n
  2. Rust already parses n -> bid_counts/ask_counts
  3. this PR restores the missing Python/PyO3 subscription lifecycle so strategies can actually receive it

The core files to review are:

  • nautilus_trader/adapters/hyperliquid/data.py
  • crates/adapters/hyperliquid/src/python/websocket.rs
  • tests/integration_tests/adapters/hyperliquid/test_data.py

Validation

Ran successfully:

  • python/generate_stubs.py
  • PYO3_ONLY=1 BUILD_MODE=debug uv run --active --no-sync build.py
  • pytest tests/integration_tests/adapters/hyperliquid/test_data.py
  • pre-commit run --files crates/adapters/hyperliquid/src/python/websocket.rs nautilus_trader/adapters/hyperliquid/data.py nautilus_trader/core/nautilus_pyo3.pyi python/nautilus_trader/adapters/hyperliquid/__init__.pyi tests/integration_tests/adapters/hyperliquid/conftest.py tests/integration_tests/adapters/hyperliquid/test_data.py

Also verified with a live TradingNode + Strategy probe against a mock Hyperliquid websocket payload containing n:

  • saw_deltas=True
  • saw_depth=True
  • bid_counts=[3, 2, 0, 0, 0, 0, 0, 0, 0, 0]
  • ask_counts=[2, 3, 0, 0, 0, 0, 0, 0, 0, 0]

That confirms the strategy-facing PyO3 path now receives and correctly parses Hyperliquid n.

@cjdsellers cjdsellers changed the title fix(hyperliquid): expose depth10 counts to PyO3 strategies Fix Hyperliquid PyO3 order book depth subscriptions Jul 4, 2026
@cjdsellers

Copy link
Copy Markdown
Member

Thank you once again @graceyangfan 👍

@cjdsellers cjdsellers merged commit 9e97eba into nautechsystems:develop Jul 4, 2026
25 checks passed
@graceyangfan graceyangfan deleted the codex/hyperliquid-depth10-fix branch July 4, 2026 23:37
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.

2 participants