How to Prevent Liquidation Risk on a Hyperliquid Perpetuals Bot
Cross-margin accounts on Hyperliquid can cascade liquidations across positions if one leg moves against you. This post details maintenance margin monitoring, auto-deleverage awareness, and hedge triggers that keep your bot solvent.
Cross-margin on Hyperliquid is a sharp tool. It lets a bot deploy capital efficiently across multiple perpetual positions from a single collateral pool, but that same pooling means a violent move on one instrument drains equity for every other open leg simultaneously. If your bot does not actively monitor margin health and act on it, a liquidation is not a matter of if — it is a matter of when the next 15% wick arrives.
Understanding Hyperliquid's Margin Model
Hyperliquid uses a portfolio cross-margin system where your unrealized PnL on winning positions can offset margin requirements on losers, but only up to a point. Every position carries an initial margin requirement (the collateral locked at entry) and a maintenance margin requirement (the minimum equity fraction before the engine liquidates).
The critical number to internalize: maintenance margin on most Hyperliquid perps is 0.5–2% of notional, depending on the asset tier and your open interest bracket. At 10x leverage on ETH-PERP, you have roughly 10% of equity as cushion before maintenance is breached. A 9% adverse move against your full notional wipes you out if you entered close to initial margin.
The liquidation engine does not warn you. It fires automatically when account equity falls below the sum of maintenance margins across all open positions. By the time the WebSocket pushes an accountLiquidated message, the damage is done.
Continuous Margin Health Polling
Your bot must poll or stream account state and calculate a margin ratio on every heartbeat:
margin_ratio = account_equity / sum(maintenance_margin_i for all open positions)
A ratio above 3.0 is comfortable. Below 1.5, your bot should be in defensive mode. Below 1.2, it should be reducing exposure aggressively. Never let the ratio touch 1.0 in production.
Use Hyperliquid's WebSocket user channel subscription — specifically the webData2 message — to get real-time account state including marginSummary.accountValue and per-position marginUsed. Polling the REST endpoint at 1-second intervals is acceptable for lower-frequency strategies but introduces latency risk during fast markets. For bots running leverage above 5x, the WebSocket path is not optional.
Set three thresholds, not one: a monitoring alert (ratio 2.0), a soft defensive trigger (ratio 1.5), and a hard reduce trigger (ratio 1.2). Each threshold should fire a distinct action — log + notify, reduce new position sizing, and execute active deleveraging, respectively. This is the architecture we use in the automated trading bots we build at TierZero.
Auto-Deleverage (ADL) and Why It Bites Bots Differently
Hyperliquid runs an auto-deleverage queue as a backstop when the insurance fund cannot cover a liquidated account's losses. Profitable positions at high leverage get forcibly closed at the bankruptcy price of the liquidatee — no slippage model, no warning, just a flat close.
For a human trader this is surprising. For a bot with complex position state, it can be catastrophic: ADL may close one leg of a hedge, leaving the other leg fully exposed without the bot detecting it through its normal order-fill logic.
The fix is defensive reconciliation. After every fill event — including fills your bot did not originate — run a position reconciliation loop that compares expected state against the exchange's reported open positions. If a position appears closed without a matching internal order, treat it as an ADL event and immediately evaluate whether any remaining positions are now unhedged.
Hyperliquid surfaces your ADL queue ranking in the account data. A rank in the top quartile means you are a candidate. When your bot sees this, it should automatically reduce leverage on profitable positions even before a liquidation event occurs elsewhere.
Hedge Triggers and Correlated Drawdown
Many perpetuals bots run delta-neutral or near-neutral books — long one asset, short a correlated asset. The risk is correlation breakdown under stress. BTC and ETH historically move together, but in sharp deleveraging events the beta relationship can temporarily invert or spike, destroying the hedge assumption precisely when you need it most.
Build a rolling correlation monitor into your bot. Track the 1-hour rolling Pearson correlation between your hedged instruments. If correlation drops below your threshold (say, 0.7 for a pair you assumed 0.9), the hedge is compromised. Your bot should respond by:
- Tightening stop losses on both legs independently
- Reducing position size proportionally to the correlation degradation
- Flagging the regime change for a manual review queue if the strategy runs unattended
Avoid the common mistake of treating hedge triggers as binary. A partial correlation breakdown warrants a partial response. Atomic deleverage of one full leg while leaving the other open is usually worse than a proportional reduction on both.
Sizing for Worst-Case, Not Expected-Case
The deepest mistake in bot risk management is calibrating position size to expected volatility rather than tail volatility. Hyperliquid perps on mid-cap assets routinely see 5–10x realized volatility spikes over short windows around liquidation cascades, oracle updates, or low-liquidity periods.
Use a volatility-scaled sizing formula: target a fixed fraction of equity at risk per position, where the denominator is a recent realized volatility estimate multiplied by a stress scalar (1.5–2.5x is a reasonable range for Hyperliquid). Recalculate sizing on every new candle close, not just at position entry. A position that was correctly sized at entry can become dangerously large if the market calms after entry and your bot adds to it using stale volatility inputs.
Also account for funding rate exposure. Persistent negative funding on a long position is a slow margin drain. A bot that holds overnight positions needs to factor cumulative funding into its margin projections, not just mark-to-market PnL.
If you want a bot that manages these controls in production rather than theory, talk to us — we build and run systems exactly like this across Hyperliquid, Solana, and Polymarket.
Need a bot like this built?
We design, build and run trading bots on Solana, Hyperliquid and Polymarket.
Start a projectMore from the blog
Public vs Paid RPC: How to Run a Fair Benchmark
A fair comparison of public and paid RPC endpoints must account for quotas, workload, freshness and support guarantees.
Read articleRPC Benchmark Percentiles Explained: p50, p95 and p99
Why averages hide the latency spikes that break trading bots, wallets and production blockchain applications.
Read articleHyperliquid REST vs WebSocket Benchmark: What to Measure
A benchmark plan for Hyperliquid market data that separates request latency from streaming freshness and recovery.
Read article