Margin and Profit Calculation (PnL)

How the exchange calculates profits in real time, what is recorded when closing a position, and how averaging works.

Two types of PnL

  • Unrealized PnL — “Paper” profit on an open position. It is recalculated from the Mark Price every second. Until the position is closed, it is only a number on the screen, not funds in your balance.
  • Realized PnL — realized profit — Profit after closing a position. It includes trading fees and funding payments. This amount is credited to your balance.

PnL Formula

Long: PnL = Size × (Mark Price − Entry Price)

Short: PnL = Size × (Entry Price − Mark Price)

Example: long ETH/USDT
Entry price3,000 USDT
Position5 ETH
Mark Price now3,400 USDT
Unrealized PnL5 × (3 400 − 3 000) = +2 000 USDT

Average Entry Price

Average Price = (Volume₁ × Price₁ + Volume₂ × Price₂) / (Volume₁ + Volume₂)
Example: Long BTC Averaging
First purchase1 BTC at 62,000
Second purchase1 BTC at 58,000
Average entry price(62,000 + 58,000) / 2 = 60,000 USDT
Unrealized PnL is not in your balance

Unrealized profits are not added to your available funds - you cannot withdraw them until you close the position.

Mark Price and Index Price

There are three prices on the exchange at the same time, and confusing them can be costly. The Last Price shows the market, while financial calculations use the Mark Price.

  • Last Price — The price of the latest trade on ABCEX. It appears in the order book and on the chart but does not affect these calculations.
  • Index Price — A fair asset price derived from external exchanges. The calculation uses their best bid and ask prices and weights the result by daily volume. It is updated once per second.
  • Mark Price — The price used to calculate margin, PnL, liquidation, and funding. It is based on the Index Price and is also updated once per second.
Why use a separate price?

If liquidation were based on the last trade, a sudden outlier in a thin order book, whether accidental or intentional, could liquidate positions. The Mark Price uses data from several external exchanges, so a price spike on one exchange has little effect.

Bottom line: the liquidation price is compared with the Mark Price, not the Last Price shown on the chart. A position can therefore be liquidated even when the candle does not reach the displayed liquidation price, and vice versa. Use the liquidation price shown in the interface because it already accounts for these factors.

Exchange outliers are excluded automatically

If an external exchange's price deviates from the index by more than 1%, it is excluded and its weight is redistributed among the other exchanges. The same applies when an exchange stops providing data.