Sub topic 13
Liquidation
This chapter assumes you know what margin and leverage are, what a perpetual swap is, and how mark price differs from last traded price. It also assumes you can read short Python functions. It covers when an exchange closes a leveraged position, how to estimate that price, and what makes the real number differ from the estimate.
What liquidation is
Leverage means you post only part of a position's value as collateral. That collateral is your margin. If the market moves against you, your losses eat into the margin. The exchange does not want a trader's losses to exceed the collateral, because the exchange or other traders would cover the difference. So it sets a minimum collateral level, the maintenance margin, and closes your position by force once your equity falls to it. That forced close is a liquidation.
Two numbers matter:
- Equity is your margin plus unrealized profit or loss on the position.
- Maintenance margin is the minimum equity the exchange requires, usually a percentage of position notional (quantity times price).
Liquidation triggers when equity is less than or equal to maintenance margin. Many venues show this as a margin ratio, maintenance margin divided by equity. A ratio of 100% means liquidation.
Deriving the liquidation price
Take an isolated-margin linear contract, where only the margin assigned to the position is at risk. Let L be leverage and m the maintenance margin rate. For a long of quantity q opened at entry:
- Initial margin is
q * entry / L. - Equity at price
Pisq * entry / L + q * (P - entry). - Maintenance margin is
m * q * P.
Setting equity equal to maintenance margin and solving for P gives P = entry * (1 - 1/L) / (1 - m). The short case flips the signs and gives P = entry * (1 + 1/L) / (1 + m). The quantity q cancels, so the liquidation price depends only on entry, leverage, and the maintenance rate.
def liquidation_price(entry, leverage, mmr, side):
"""Isolated-margin linear contract, ignoring fees and funding."""
if side == "long":
return entry * (1 - 1 / leverage) / (1 - mmr)
return entry * (1 + 1 / leverage) / (1 + mmr)
def margin_ratio(entry, qty, leverage, mmr, side, price):
"""Maintenance margin divided by equity. 1.0 or more means liquidation."""
sign = 1 if side == "long" else -1
margin = qty * entry / leverage
equity = margin + sign * qty * (price - entry)
maintenance = mmr * qty * price
return float("inf") if equity <= 0 else maintenance / equity
liq = liquidation_price(60000, 10, 0.005, "long")
print(round(liq, 2))
for p in (60000, 57000, liq):
print(round(p, 2), round(margin_ratio(60000, 1.0, 10, 0.005, "long", p), 4))The liquidation price comes out near 54,271.36. The margin ratio is 0.05 at entry, 0.095 at 57,000, and about 1.0 at the liquidation price. The 10% adverse move you might expect from 10x leverage is cut to about 9.55%, because the maintenance requirement uses part of your margin before the position is closed.
How leverage moves the line
Higher leverage puts the liquidation price closer to entry. Using the same formula for a long at 60,000 with a 0.5% maintenance rate:
| Leverage | Liquidation price | Distance from entry |
|---|---|---|
| 2x | 30,150.75 | about 49.8% |
| 5x | 48,241.21 | about 19.6% |
| 10x | 54,271.36 | about 9.5% |
| 20x | 57,286.43 | about 4.5% |
At 20x, a price move smaller than a routine daily range in crypto can wipe out the position.
What triggers it: mark price, not last price
Exchanges compare your position against the mark price, not the last traded price. The mark price is built from the index price (a weighted spot price from several venues), usually with a smoothed funding-basis adjustment. This stops one thin trade or a manipulated order book from liquidating many accounts. A brief wick on the venue's own order book may not liquidate you if the mark price barely moves. A move in the index across other venues can liquidate you even when the local last price looks calm.
The liquidation process
Procedures differ by venue, but most follow this sequence.
The bankruptcy price is where equity reaches zero. For the 10x long above it is entry * (1 - 1/L), or 54,000. The gap between 54,271.36 and 54,000 is the cushion. The engine tries to close the position inside that gap and pays a liquidation fee from it. If it closes above 54,000, the leftover goes to the insurance fund. If it closes below, the fund absorbs the loss. If the fund runs dry, auto-deleveraging (covered in the next chapter) forces profitable counterparties to close.
Some venues liquidate in steps. They cut the position size to bring the margin ratio back under the limit rather than closing everything. This lowers the chance of a total loss on large positions.
Isolated and cross margin
In isolated mode, the loss is capped at the margin you assigned to that position. In cross mode, the whole account balance backs all positions, so the liquidation price sits much further away. But a single bad position can drain every other asset in the account. Cross margin is safer against short spikes and more dangerous when a trade keeps going wrong.
Why the real price differs from the formula
Treat the function above as an estimate. Several factors move the real number:
- Fees. Opening and closing fees reduce equity. Some venues reserve the expected closing fee in the maintenance requirement.
- Funding. Funding payments are taken from or added to your margin. A long paying positive funding for days moves its liquidation price closer to the market.
- Tiered maintenance rates. Larger notional sizes carry higher maintenance rates, so big positions liquidate sooner than the flat rate suggests.
- Other positions in cross mode. Their unrealized PnL changes your equity.
- Inverse contracts. Margin is held in the base coin, so collateral value falls as price falls. The liquidation price formula uses reciprocals and is not linear.
Edge cases
- Gaps and fast markets. If price jumps through the liquidation price, the engine may fill the position worse than the bankruptcy price, and the insurance fund pays the shortfall.
- Order book depth. A large liquidation sells into a thin book, pushing price lower and triggering further liquidations. This chain is a liquidation cascade.
- Stop-loss versus liquidation. A stop-loss that triggers before the liquidation price lets you exit on your terms. Place it with enough room that the fill still lands above the liquidation price.
- Venue differences. Maintenance rates, fees, partial liquidation rules, and the mark price formula all vary. Check the venue's documentation before relying on any estimate.
Exercise
A trader opens a short on ETH at 2,000 with 5x leverage on an isolated-margin linear contract. The maintenance margin rate is 1%. Ignoring fees and funding, what is the estimated liquidation price, and what is the bankruptcy price?
Show answer
Liquidation price = entry (1 + 1/L) / (1 + m) = 2000 1.2 / 1.01 = 2400 / 1.01, about 2,376.24. Bankruptcy price = entry * (1 + 1/L) = 2,400. The 23.76 gap between them is the cushion that covers the liquidation fee and execution slippage.
Exercise
A long position at 60,000 is moved from 10x to 20x leverage, with a 0.5% maintenance rate. Does the liquidation price move toward or away from entry, and by roughly how much?
Show answer
It moves toward entry. At 10x it is about 54,271.36 and at 20x it is about 57,286.43, so the stop-out point rises by about 3,015 (roughly 5 percentage points of price distance).