How Hyperliquid Calculates Perpetual and Spot Entry Prices and PnL
Summary
The document explains that Hyperliquid presents entry price and profit-and-loss figures as convenience calculations, while its underlying accounting relies on margin for perpetuals, balances for spot, and trade records. For perpetual positions, trades that increase the absolute position size are treated as openings: entry price is updated using a size-weighted average of the previous entry and new trade price. Trades that reduce a position leave entry price unchanged. Unrealized PnL uses mark price relative to entry price and position direction; closed PnL combines the closing trade’s fee with its price-based result, while opening trades contribute only their fee.
Spot applies the same basic formulas, with buys treated as openings and sells as closings. Transfers are priced at mark price, while genesis distributions use a specified market-cap-based entry convention. The document notes that a zero entry price for such distributions would make return on equity undefined. Existing spot balances receive an entry price based on the first trade or transfer after the feature began, so historical cost basis may not be available.
Key ideas
- Perpetual trades that enlarge a position update entry price using a size-weighted average.
- Closing perpetual trades preserve the existing entry price.
- Unrealized PnL depends on mark price, entry price, position size, and whether the position is long or short.
- Spot buys and sells are treated as openings and closings, respectively, with special conventions for transfers and genesis distributions.
- Some existing spot balances use a cost basis established only after the feature was enabled.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.