Sub topic 7
Mark price versus last price and why liquidations use it
This chapter assumes you know what a perpetual futures contract is, how a liquidation price is calculated, and how to read short Python functions. You should also know that an exchange compares your equity to a maintenance requirement. The previous chapters used "the price" as if there were only one. This chapter shows that an exchange tracks several prices, and that the one used to liquidate you is usually not the one on the chart.
Two prices, two jobs
The last price is the price of the most recent trade on the perpetual contract's own order book. It tells you what someone just paid. It is easy to move, because one large market order in a thin book can print a trade far from where the market has been trading.
The mark price is the exchange's estimate of the contract's fair value. It is computed from outside reference prices instead of from the contract's own last trade. Exchanges use it for three things:
- Calculating unrealized profit and loss.
- Deciding when a position is liquidated.
- Triggering stop orders, if you choose a mark-price trigger.
The index price is a composite spot price. It is built from several independent spot exchanges and feeds into the mark price.
| Price | Source | Easy to spike? | Typical use |
|---|---|---|---|
| Last price | Latest trade on the perpetual order book | Yes | Chart, fills, "last" stop triggers |
| Index price | Aggregate of spot prices on several exchanges | Hard | Input to mark price, funding calculation |
| Mark price | Index price plus a smoothed perpetual premium | Hard | Unrealized PnL, liquidation, "mark" stop triggers |
Why the last price is a poor liquidation trigger
Suppose a liquidation engine used the last price. An attacker, or an ordinary forced seller, could then trigger liquidations in two steps:
- Sell hard into a thin order book so that a single print lands below many traders' liquidation prices.
- Collect the profit from the liquidations that follow, because forced buying and selling continues the move.
A single wick would wipe out positions that were fine by any reasonable measure of the market. The same weakness applies to ordinary volatility. A momentary gap in the order book, a fat-finger order or a brief exchange glitch could close healthy accounts.
The mark price blunts this. To push it, you would have to move the spot market on several venues at once. You would also have to hold the move long enough to shift the smoothed premium. That costs far more than one aggressive order on a single book.
How a mark price is built
Every exchange publishes its own formula, and the formulas differ in detail. Most share a two-part structure:
- Compute an index price from spot quotes on several venues. Many use a weighted average, a median, or a trimmed average that discards outliers.
- Add a smoothed basis. The basis is the gap between the perpetual's own price (often the mid of the best bid and ask) and the index. An exponential moving average (EMA) smooths it, so a short-lived premium cannot jerk the mark around.
Written as a formula:
mark price = index price + EMA of (perpetual mid price − index price)
When the perpetual trades at a persistent premium to spot, the mark sits slightly above the index. A one-second spike in the perpetual's price barely changes the EMA, so the mark ignores it.
A runnable sketch
The code below uses a median for the index and a simple EMA for the basis. It is a teaching model, not any exchange's real formula. It shows how one bad spot quote affects each choice of aggregation.
from statistics import mean, median
def index_price(spot_quotes):
"""Median of spot quotes from several venues. Robust to one bad feed."""
return median(spot_quotes.values())
def ema_update(previous, value, alpha=0.2):
"""One step of an exponential moving average."""
return alpha * value + (1 - alpha) * previous
def mark_price(index, ema_basis):
"""Index price plus the smoothed perpetual premium."""
return index + ema_basis
spot = {"A": 100.2, "B": 100.0, "C": 100.1, "D": 87.0} # venue D prints a bad quote
print("mean of quotes :", round(mean(spot.values()), 3)) # 96.825, dragged down
idx = index_price(spot)
print("median index :", round(idx, 3)) # 100.05
perp_mid = 100.30
basis_now = perp_mid - idx # 0.25
ema_basis = ema_update(previous=0.15, value=basis_now) # 0.17
print("mark price :", round(mark_price(idx, ema_basis), 3)) # 100.22The bad quote from venue D moves the mean by more than 3 points. It does not move the median. The perpetual's premium of 0.25 moves the mark by only 0.17, because the EMA blends it with the earlier value of 0.15.
Applying it to a liquidation
Use the earlier example: a 10x isolated long entered at 100 with a 0.5% maintenance rate, which has a liquidation price of about 90.45. The next code checks that position against two prices.
def liquidation_price(entry, leverage, maintenance_rate, side):
"""Approximate liquidation price for an isolated linear position."""
initial = 1.0 / leverage
if side == "long":
return entry * (1 - initial) / (1 - maintenance_rate)
if side == "short":
return entry * (1 + initial) / (1 + maintenance_rate)
raise ValueError("side must be long or short")
def is_liquidated(side, liq_price, trigger_price):
"""A long is liquidated at or below its liquidation price, a short at or above."""
if side == "long":
return trigger_price <= liq_price
return trigger_price >= liq_price
liq = liquidation_price(100.0, 10, 0.005, "long") # about 90.45
# Scenario 1: a wick prints on the perpetual book, but the index barely moves.
last_wick, mark_during_wick = 89.5, 91.2
print(is_liquidated("long", liq, last_wick)) # True (a last-price engine would liquidate)
print(is_liquidated("long", liq, mark_during_wick)) # False (a mark-price engine does not)
# Scenario 2: spot really falls, and the last price lags above the mark.
last_price, mark_price_now = 90.9, 90.3
print(is_liquidated("long", liq, last_price)) # False
print(is_liquidated("long", liq, mark_price_now)) # TrueScenario 1 shows the protection. A sharp wick on one order book does not close your position. Scenario 2 shows the cost. If spot really falls, the mark can reach your liquidation price while the contract's last price still looks safe on your chart. In practice the chart can show a price above your liquidation level at the moment you are liquidated.
Effects beyond liquidation
- Unrealized PnL. Your displayed profit and loss, and therefore your equity, is computed from the mark. A position can look better on a chart than it does in your margin calculation.
- Stop orders. Many exchanges let you choose whether a stop triggers on the last price or the mark price. A last-price stop reacts to wicks on the contract. A mark-price stop is harder to trigger by accident but fires later in a fast market.
- Funding. The funding rate depends on the premium of the perpetual to the index. That is the same basis input that feeds the mark, so the two prices stay linked.
- Realized PnL. When you close, you are paid at the actual fill price. Mark price decides when you are liquidated, but it does not decide what you receive on exit. The forced order is a real order, and it can fill worse than the mark.
Failure modes and gotchas
The mark is not immune to manipulation. If the index uses only a few venues, or includes a thinly traded one, attackers can target those spot markets. Some small-cap tokens have been exploited this way. Better index designs use many venues, weight by liquidity and drop outliers.
Feeds can fail. If a spot venue goes offline, the index must drop it or fall back to others. A badly handled outage can produce a stale or distorted index. Exchanges differ in how they handle this, and the rules are in their documentation.
The mark can lag a real move. Smoothing is the feature that blocks wicks. It also means the mark responds slowly when the perpetual's premium or discount to spot changes sharply and stays changed. In a crash, the perpetual can trade well below spot while the mark moves only part of the way toward it. This protects longs, but the delay can reverse as the EMA catches up.
Liquidation does not guarantee a fill at the mark. The mark triggers the liquidation. The forced order then goes to the book or the engine, as the next chapter explains. If the book is thin, the closing price can differ from the mark, and the difference feeds the insurance fund or becomes a loss.
Venues differ. The aggregation method, the smoothing window, and whether a venue offers a choice of trigger price all vary. Read the contract specification of the exchange you use. Do not assume the formulas above apply as written.
Exercise
A 5x isolated short is entered at 200 with a 1% maintenance rate. Its liquidation price is 200 * (1 + 1/5) / (1 + 0.01), which is about 237.62. The last price on the perpetual spikes to 240 for one second, while the mark price stays at 205. A moment later, spot really rises and the mark reaches 238 while the last price shows 236. In which of the two moments is the position liquidated under a mark-price engine, and why would a last-price engine behave differently?
Show answer
Under a mark-price engine, the spike to 240 does not liquidate the position, because the mark is only 205, below 237.62. The position is liquidated in the second moment. A short is liquidated when the trigger price is at or above its liquidation price, and the mark of 238 is above 237.62, even though the last price of 236 is below it. A last-price engine would do the opposite: it would liquidate on the one-second spike to 240 and would not liquidate in the second moment.