Skip to main content

Unrealized PnL

This is algebraically the same as SizeUsd x (MarkPrice - EntryPrice) / EntryPrice, just rearranged to avoid precision loss in Solidity’s integer math. A positive result is profit, negative is loss.
PnL uses mark price, not the last traded price. See Mark Price & Index Price for how mark price is derived.

Liquidation price (isolated)

where MaintenanceMargin = SizeUsd x MaintenanceMarginBps / 10,000 for that market.
If a long position is so well collateralized that the formula would produce a negative result, its liquidation price is effectively 0 (it can’t be liquidated by price alone). The equivalent case for a short position returns an effectively unreachable maximum, for the same reason.

Worked example

A 65,000longposition,entryprice65,000 long position, entry price 64,800, in a market with a maintenanceMarginBps of 50 and $6,500 collateral:

Liquidation price (cross)

Isolated positions each have their own liquidation price, computed on their own collateral alone. Cross positions don’t work quite the same way, because liquidation is decided at the account level, not per position. For a single cross position, Perpetra can still show you a liquidation price, but it’s computed by holding every other cross position’s PnL fixed at its current price and solving for the price at which this one position’s move would tip your whole cross account into liquidation. If any of your other cross positions move, that number shifts too. See Margin Modes for the full account-level liquidation check.

What triggers an actual liquidation

Meeting the liquidation price condition makes a position eligible for liquidation. It isn’t liquidated automatically the instant that happens. A liquidation keeper watches all open positions and calls Perpetra’s liquidation contract once a position (or, for cross positions, the account) crosses the threshold. See Keeper System and Liquidation Engine for that side of it.