Unrealized PnL

Unrealized profit and loss is what an open position is worth above or below its entry price, measured at the mark price, before anything is closed.

Definition

The figure is the price difference times the size, signed by the side, and Hyperliquid measures it on the mark price rather than on the book. One caution the documentation gives is worth keeping: on the Hyperliquid DEX, entry price, unrealized pnl and closed pnl are purely frontend components provided for user convenience, and the fundamental accounting is based on margin and trades. The number is a reading of a position, not a balance.

The entry price it is measured from moves only when the position grows. A perp trade is considered opening when the absolute value of the position increases, which is longing while long or shorting while short; on an opening trade the entry price becomes the average of the current entry price and the trade price, weighted by size. On a closing trade the entry price is kept the same, so closing part of a position does not change the price the rest is measured from.

What the figure does next depends on the margin mode. On a cross position, unrealized profit is automatically available as initial margin for new positions and unrealized loss is taken from the collateral behind every other cross position, and the whole account value, unrealized profit and loss included, is what the liquidation test reads. On an isolated position it is applied as additional margin for that position alone. Taking profit out is bounded: what remains must be at least 10% of the total notional of every open position and still meet the initial margin requirement. The figure counts the price and nothing else: the fees already paid and the funding already settled are cash, and are not in it.

Formula

unrealized_pnl = side * (mark_price - entry_price) * position_size, with side = 1 for a long and side = -1 for a short.

Example

An example, in round figures. A long of 1 BTC entered at $100,000 with the mark price at $105,000 shows an unrealized profit of 1 times $5,000, so $5,000. Held at 10x, the margin behind it was $10,000, so that is half of the margin on a move of 5% in the price. A short of the same size at the same two prices shows the same figure with the other sign, a loss of $5,000.