Perp Liquidation Gate
perp_gateDeterministic perpetual-futures risk. Given a position (entry, size, margin/leverage, maint-margin/maxLeverage), returns the exact liquidation price, the % adverse move to liquidation, effective leverage, and (if a funding rate is given) the funding drag. Pass a Hyperliquid symbol (e.g. BTC) to auto-fill live mark price, funding, and max leverage. Includes a self-check proving the liquidation invariant. Call this BEFORE opening or sizing any leveraged perp position — an agent that knows its true liquidation distance does not get surprise-liquidated.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| side | No | long | short (buy | sell are accepted synonyms, as is -1 for short); default long | |
| size | No | position size in base units (or pass notional) | |
| venue | No | live-data venue (default hyperliquid). The maths is venue-agnostic — for any other venue omit this and pass maxLeverage/markPrice/fundingRateHourly yourself. | |
| margin | No | isolated margin posted (or pass leverage) | |
| symbol | No | perp symbol (e.g. BTC) — auto-fills live markPrice, fundingRateHourly, and the margin source (Hyperliquid notional tiers or dYdX maintenance rate); also defaults entryPrice to the live mark | |
| leverage | No | position leverage (alternative to margin) | |
| notional | No | position notional in quote/USD | |
| markPrice | No | current mark; distance-to-liq measured from here | |
| entryPrice | No | defaults to live mark if a symbol is given | |
| maxLeverage | No | venue max leverage for the asset | |
| horizonHours | No | horizon for the funding-drag estimate, in hours | |
| maintMarginRate | No | e.g. 0.0125; or pass maxLeverage (mmr = 0.5/maxLeverage) | |
| fundingRateHourly | No | hourly funding rate (Hyperliquid funds hourly) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ok | No | false when the engine rejected the input | |
| model | No | model assumptions used | |
| proof | No | Verifiability envelope: echoed inputs, engine codeHash, contentHash of this exact result, self-checks, EIP-712 signature (EAS-ready). Re-run the open engine on `inputs` to reproduce the result byte-for-byte. | |
| checks | No | Ground-truth self-checks; the result is untrustworthy if any fails. | |
| funding | No | funding drag over the horizon (when a funding rate is given) | |
| marginTier | No | venue margin tier the notional falls into | |
| liquidationPrice | No | exact price at which the position liquidates | |
| effectiveLeverage | No | notional / margin actually run | |
| initialMarginRatePct | No | initial margin rate applied (%) | |
| moveToLiquidationPct | No | adverse % move (from mark) that triggers liquidation | |
| maintenanceMarginRatePct | No | maintenance margin rate applied (%) |