hyperliquid.assets.perpetual_margin_events table contains one row per event on an isolated-margin perpetual position, for native Hyperliquid perps and HIP-3 perps. An event is a fill, an isolated margin adjustment (margin added to or removed from the position) or a leverage update. Every fill on an isolated position is listed, including the closing fill. Margin adjustments and leverage updates are listed while the position is open, or while position_size is null. Cross-margin positions, and events while a position is in cross margin, are not included.
Each row gives the position after the event: its size, its leverage, and margin_contributed, the margin held in the position excluding unrealized PnL. For an isolated position this is the value Hyperliquid’s clearinghouseState reports as marginUsed minus unrealizedPnl. Hyperliquid’s API reports only the current value; this table gives its history.
Amounts are denominated in the market’s collateral token: USDC on native perps, and the HIP-3 DEX’s collateral token on HIP-3 markets (for example USDE, USDH, USDT0). Do not treat those columns as USD unless the collateral token is a dollar stablecoin at peg. Perpetual Funding Events carries the collateral_token of each coin.
Coverage starts at 2025-07-10 UTC.
Table Details
Always filter with
WHERE user = .... User-scoped queries are the supported access pattern.Margin Values
Rows of oneuser and coin are ordered by timestamp, then event_sequence. In that order, margin_contributed equals the previous row’s margin_contributed plus funding_since_previous_event, snapshot_adjustment_since_previous_event and margin_contributed_change. The sum does not hold when one of these values is null, across events that are not listed (events while the position was in cross margin, and margin adjustments and leverage updates on a flat position), or where the previous row shows the position still open but the next fill opens it from flat, because the closing event is not listed.
margin_quality describes each row’s margin_contributed:
A position snapshot is Hyperliquid’s own record of a position’s state, which Allium stores at regular intervals in
hyperliquid.raw.perpetual_positions. Where a snapshot is available, values are checked against it, and any difference appears on the position’s next row in snapshot_adjustment_since_previous_event. Rows with is_best_effort set are older than the first position snapshot available for their HIP-3 DEX or for native perps (2025-09-22 for native perps, 2025-12-08 or later for HIP-3 DEXs), so their values could not be checked against one.
Mark Price
mark_price is the mark price in effect after the latest on-chain price update before the event. Hyperliquid publishes mark prices on chain about every 3 seconds. The mark Hyperliquid applies at the exact instant of an event can differ from this value, usually by a fraction of a basis point to a few basis points.
position_valueandmargin_usedare valued atmark_price, so they approximate Hyperliquid’s own values at the event.- When a fill opens, increases or flips a position at a price worse than the mark price, Hyperliquid moves extra margin into the position to cover the immediate loss against the mark. Rows after such a fill are
estimated. mark_priceis null when no recent mark price is available.
Known Limitations
- Hyperliquid transactions do not carry the vault or sub-account address. A margin adjustment or leverage update signed for a vault or sub-account is recorded under the signing wallet, and the vault’s or sub-account’s margin can be off until its next position snapshot.
- After a
topUpIsolatedOnlyMarginaction, the margin is unknown until the position’s next snapshot. - A margin addition sent in the same block as the fill that opens the position can be missing until the position’s next snapshot.
- A change of margin mode that is not an
updateLeverageaction, for example a HIP-3 deployer changing a market’s margin mode, is reflected only once a later position snapshot shows it. - A wallet whose isolated setting on a market predates the available history, and was never changed, can be missing until a position snapshot shows the position as isolated.
Margin of Closed Positions
Perpetual Closed Positions has no margin columns. For an isolated position, match its rows in this table onuser, coin and timestamp between open_time and close_time. Cross-margin positions have no rows here, so the query below keeps them with null margin columns. When one position closes and the next opens in the same timestamp, rows at that timestamp match both positions.