Expand description
Isolated margin accounting for simulated perpetual futures.
Models per-instrument isolated margin positions:
- Tracks qty, avg entry price, leverage, reserved margin
- Computes unrealized PnL at any mark price
- Computes liquidation price using the Hyperliquid formula
- Determines required initial margin for new orders
The MarginLedger manages all positions + free USDC, providing
a single source of truth for the simulated account.
Structsยง
- Isolated
Position - Per-instrument isolated margin position.
- Margin
Ledger - Manages all isolated margin positions and free USDC balance.