Sub topic 2
Calculating a liquidation price
This chapter assumes you know how long and short positions work, can read simple Python, and are comfortable with percentages. Liquidation is the forced closing of a leveraged position when the trader's remaining margin falls too low. Here you will learn to estimate that price, then cover the related rules that determine when it applies.
Estimating the liquidation price
For an isolated position, the exchange closes the trade when equity (margin plus unrealized profit or loss) falls to the maintenance requirement. Solving that equation gives an approximate price.
def liquidation_price(entry, leverage, maintenance_rate, side):
"""Approximate liquidation price for an isolated linear position.
Ignores fees, funding, and exchange-specific tiers.
"""
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')
print(round(liquidation_price(100.0, 10, 0.005, 'long'), 2)) # 90.45
print(round(liquidation_price(100.0, 10, 0.005, 'short'), 2)) # 109.45At 10x, a long entered at 100 is liquidated about 10% lower. The maintenance rate of 0.5% moves the result slightly.
Isolated versus cross margin
- Isolated margin assigns a fixed amount of collateral to one position. Only that collateral can be lost.
- Cross margin shares the whole account balance across positions. A position survives larger swings, but a loss can consume the entire account.
> Note: the choice of margin mode changes the liquidation formula. The calculation above applies to isolated margin only.
Mark price versus last price
Exchanges check liquidation against the mark price, a fair-value estimate built from several spot markets, not the last price of the most recent trade. This prevents a single unusual trade, or a brief wick, from liquidating positions unfairly.
Funding rates and the cost of holding
Perpetual futures have no expiry, so exchanges use a funding rate, a periodic payment between longs and shorts that keeps the contract price near the spot price. When the rate is positive, longs pay shorts. On a 10,000 notional position at 0.01% per 8 hours, the long pays 1 per period. This cost reduces equity and moves the liquidation price closer.
What happens at liquidation
Liquidation carries a fee. If the position closes at a loss larger than the posted margin, the insurance fund (a reserve built from past liquidation fees) absorbs the difference. If that reserve runs out, the exchange auto-deleverages profitable traders on the other side.
Exercise
A trader opens a 5x long at 200 with a 0.5% maintenance rate. Using the formula above, what is the approximate liquidation price, and would it change under cross margin?
Show answer
200 × (1 − 0.2) / 0.995 ≈ 160.80. Under cross margin the formula changes, because the whole account balance backs the position, so this isolated estimate no longer applies.