The most critical module in the system. All formulas must maintain ≥95% consistency with HL.
All calculations must align with HL precision, fetched from HL meta API and cached:
| Parameter | Source | Notes |
|---|---|---|
| Price precision (szDecimals) | HL /info meta API |
Per-asset; BTC=1 decimal |
| Size step | HL /info meta API |
Minimum order size and increment |
| Maintenance margin rate tiers | HL /info meta API |
Tiered by notional size |
Precision rules synced hourly.
Each position has an independent margin pool. Liquidations are isolated and do not affect other positions.
Initial Margin = Notional Value / Leverage = size × entry_price / leverage
Example (BTC):
Notional < $100K → Rate 0.4%
Notional $100K–$1M → Rate 0.6%
Notional > $1M → Rate 1.0%
Must be fetched from HL API. Never hardcode.
Isolated Long:
Liq Price = entry_price × (1 - (margin - cumulative_funding_paid) / notional + maintenance_rate)
Isolated Short:
Liq Price = entry_price × (1 + (margin - cumulative_funding_paid) / notional - maintenance_rate)
When: (position_margin + unrealized_pnl) ≤ notional × maintenance_rate
→ Trigger liquidation for this position; other positions unaffected
All cross positions share account equity. A loss in one position affects the liquidation threshold of others.
Account Equity = Wallet Balance + Σ(all cross position unrealized PnL)
Cross Maintenance Req = Σ(notional × maintenance_rate per cross position)
Account Equity ≤ Cross Maintenance Req → Trigger account-level liquidation
Users can hold both isolated and cross positions simultaneously:
Available = Wallet Balance - Σ(isolated margins) + Σ(cross unrealized PnL)
Applies to both INTERNAL and HYPERLIQUID positions. Platform is the sole liquidation authority.
| Position Type | Method | Platform P&L |
|---|---|---|
| INTERNAL | L3 internal settlement at mark price | Platform earns user margin (80/20 split) |
| HYPERLIQUID | Send market close to HL → await receipt → settle at close_price | No additional client loss |
User margin zeroed
Realized PnL recorded
INTERNAL: 80% → platform profit, 20% → risk reserve
Position status → LIQUIDATED
Push liquidation notification to user