Skip to content

Fix HYPE sell clamp using master wallet free balance#41

Merged
palm-octo-chainsaw merged 2 commits into
masterfrom
fix-hype-free-balance-clamp
May 20, 2026
Merged

Fix HYPE sell clamp using master wallet free balance#41
palm-octo-chainsaw merged 2 commits into
masterfrom
fix-hype-free-balance-clamp

Conversation

@palm-octo-chainsaw
Copy link
Copy Markdown
Owner

Summary

  • _execute_hype was clamping sell sizes against ccxt.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 to 0, and Hyperliquid rejected them with Order has zero size.
  • Switched the clamp to Balance.get_hyperliquid_free_balance("HYPE"), which reads total - hold from spotClearinghouseState at META_MASK — the same source already used for portfolio valuation.
  • Added a defensive if trade_amount <= 0: skip guard so zero-size submissions never reach the exchange.
  • Patch bump v1.5.0v1.5.1.

How it broke

Observed in prod logs at 2026-05-20 00:16:56: signal cut HYPE 26.1% → 8.3%, rebalance computed sell ~33 HYPE, but the clamp produced SELL 0.0 and Hyperliquid rejected. Live API confirmed spotClearinghouseState@META_MASK shows HYPE present while ccxt.fetch_balance()@HYPERLIQUID_ACCOUNT_ADDRESS returns {HYPE: None}.

Test plan

  • pytest — 57 passed (including 2 new regression tests for the agent/master wallet split and the zero-free skip)
  • After deploy: verify next HYPE rebalance executes successfully (or skips cleanly when free=0)

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.
@palm-octo-chainsaw palm-octo-chainsaw self-assigned this May 20, 2026
- 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
@sonarqubecloud
Copy link
Copy Markdown

@palm-octo-chainsaw palm-octo-chainsaw merged commit 16d8449 into master May 20, 2026
5 checks passed
@palm-octo-chainsaw palm-octo-chainsaw deleted the fix-hype-free-balance-clamp branch May 20, 2026 18:02
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.

1 participant