Fix Hyperliquid PyO3 order book depth subscriptions#4381
Merged
cjdsellers merged 1 commit intoJul 4, 2026
Merged
Conversation
Member
|
Thank you once again @graceyangfan 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the Hyperliquid Python/PyO3 order book depth path so live strategies can receive venue level order counts (
n) throughOrderBookDepth10.bid_counts/ask_counts.Before this change:
nnAfter this change:
subscribe_order_book_depth(...)works in the Python live clientOrderBookDepth10with populatedbid_counts/ask_countsWhat changed
_subscribe_order_book_depth(...)and_unsubscribe_order_book_depth(...)in the Python live data client.subscribe_book_snapshots(...)to callsubscribe_book_depth10(...)instead of reusingsubscribe_book(...).unsubscribe_book_snapshots(...)and synced both.pyisurfaces.Why this approach
This keeps the fix adapter-local and consistent with existing Nautilus Trader design:
ninto deltasOrderBookDepth10.bid_counts/ask_countssurfaceReviewer notes
The important contract is:
l2Bookalready carriesnn -> bid_counts/ask_countsThe core files to review are:
nautilus_trader/adapters/hyperliquid/data.pycrates/adapters/hyperliquid/src/python/websocket.rstests/integration_tests/adapters/hyperliquid/test_data.pyValidation
Ran successfully:
python/generate_stubs.pyPYO3_ONLY=1 BUILD_MODE=debug uv run --active --no-sync build.pypytest tests/integration_tests/adapters/hyperliquid/test_data.pypre-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.pyAlso verified with a live
TradingNode + Strategyprobe against a mock Hyperliquid websocket payload containingn:saw_deltas=Truesaw_depth=Truebid_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.