Fix HYPE sell clamp using master wallet free balance#41
Merged
Conversation
The agent wallet (HYPERLIQUID_ACCOUNT_ADDRESS) used to sign orders holds no funds — funds live at META_MASK. ccxt's fetch_balance queries the agent address and returns 0 HYPE, so the pre-trade clamp pinned sell amounts to zero and Hyperliquid rejected the orders with "Order has zero size." Use spotClearinghouseState at the master wallet (total - hold) for the free balance, and skip cleanly if the resulting size rounds to 0.
- Extract ERR_SIZE_BELOW_PRECISION constant (S1192) - Use logger.exception in Hyperliquid balance fetch (S8572) - Add tests covering get_hyperliquid_free_balance and the spotClearinghouseState fetch helper
|
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
_execute_hypewas clamping sell sizes againstccxt.fetch_balance().get("free", {}).get("HYPE", 0), which queries the agent wallet (HYPERLIQUID_ACCOUNT_ADDRESS). Funds live at the master wallet (META_MASK), so the clamp pinned sells to0, and Hyperliquid rejected them withOrder has zero size.Balance.get_hyperliquid_free_balance("HYPE"), which readstotal - holdfromspotClearinghouseStateatMETA_MASK— the same source already used for portfolio valuation.if trade_amount <= 0: skipguard so zero-size submissions never reach the exchange.v1.5.0→v1.5.1.How it broke
Observed in prod logs at
2026-05-20 00:16:56: signal cut HYPE 26.1% → 8.3%, rebalance computedsell ~33 HYPE, but the clamp producedSELL 0.0and Hyperliquid rejected. Live API confirmedspotClearinghouseState@META_MASKshows HYPE present whileccxt.fetch_balance()@HYPERLIQUID_ACCOUNT_ADDRESSreturns{HYPE: None}.Test plan
pytest— 57 passed (including 2 new regression tests for the agent/master wallet split and the zero-free skip)