Sub topic 3
Auto-deleveraging when the insurance fund is not enough
This chapter assumes you know what long and short positions are, what a liquidation price is, and how mark price differs from last price. The code uses basic Python.
When the insurance fund runs out
When a leveraged position is liquidated, the exchange closes it. If the trader's remaining equity is negative, the insurance fund covers the gap first. If the fund cannot cover it, the exchange uses auto-deleveraging (ADL). ADL force-closes profitable positions on the other side of the market at the current price, so the exchange does not spread the loss across all users.
Exchanges differ in how they rank which winners to close. A common approach ranks by profit and leverage together:
def adl_rank(positions):
"""Return positions in the order they would be deleveraged."""
return sorted(positions,
key=lambda p: p["pnl_ratio"] * p["leverage"],
reverse=True)
positions = [
{"name": "A", "pnl_ratio": 0.40, "leverage": 10},
{"name": "B", "pnl_ratio": 0.10, "leverage": 5},
{"name": "C", "pnl_ratio": 0.25, "leverage": 3},
]
for p in adl_rank(positions):
print(p["name"], round(p["pnl_ratio"] * p["leverage"], 2))
# A 4.0
# C 0.75
# B 0.5Open interest and crowded positioning as a warning sign
Open interest is the total size of contracts that are still open. When open interest rises while the funding rate stays high and positive, many traders are paying to hold the same leveraged side. A modest price move can then trigger many liquidations at once, and ADL becomes more likely.
Liquidation cascades: forced orders that move the price further
A liquidation is a forced market order. Selling from liquidated longs lowers the price, which reaches the liquidation prices of other longs. Each round adds more forced selling. The same loop runs in reverse for short squeezes.
Liquidations in DeFi lending: health factor and liquidation bonus
In DeFi lending, a health factor is collateral value times the liquidation threshold, divided by debt value. When it falls below 1, anyone can repay part of the debt and receive collateral at a discount, called the liquidation bonus. Unlike an exchange, a lending protocol has no insurance fund. Any bad debt left after collateral is seized is absorbed by lenders or the protocol's reserves.
Practical ways to limit leverage risk
- Use lower leverage. At 3x, a 10% adverse move costs about 30% of margin.
- Size each position so that a full loss is an amount you can afford.
- Keep a collateral buffer, and keep a health factor well above 1.
- Use isolated margin for speculative trades, so one position cannot drain the whole account.
Exercise
A trader opens a 10x isolated long at 100 with a 0.5% maintenance rate. What is the approximate liquidation price?
Show answer
About 90.45, roughly 10% below entry. The formula is entry × (1 − 1/leverage) / (1 − maintenance rate).