Sub topic 10
Auto-deleveraging when the insurance fund is not enough
This chapter assumes you know what a perpetual futures position is, how maintenance margin and liquidation price work, and what the insurance fund does when a position is force-closed. Basic Python is enough for the code.
Auto-deleveraging (ADL) is the last step in an exchange's loss-handling sequence. It runs only when a liquidation has produced a loss that the insurance fund cannot absorb. The exchange then forcibly closes profitable positions on the opposite side. Those traders are not in danger and did nothing wrong. Their positions are shut because the exchange needs a counterparty for the failed position.
Where ADL sits in the loss waterfall
A liquidation is meant to close a position while it still has some margin left. The exchange takes the remaining margin as a fee and sends part of it to the insurance fund. A deficit appears when the market moves faster than the liquidation engine can close the position. The position's equity has then fallen below zero, and the closing order fills at a price worse than the bankruptcy price.
The bankruptcy price is the price at which a position's equity is exactly zero. For an isolated long it is entry * (1 - 1/leverage). For a 10x long entered at 100, that is 90. The liquidation price from the earlier chapter, about 90.45, sits slightly above it. The gap between the two is the buffer the engine uses to close the position.
If the position is closed at 88 instead of 90, the 2-per-unit difference is a deficit. Exchanges cover it in a fixed order:
- The liquidated trader's remaining margin, which is already gone by this point.
- The insurance fund.
- Auto-deleveraging, or in some designs a socialized loss.
Why the fund can run out
The insurance fund is finite. It grows slowly, from liquidation surpluses, and can shrink within minutes. Three conditions make a drained fund likely:
- A thin order book. When bids disappear during a sell-off, a liquidation order for a large long walks far down the book before it is filled.
- Many liquidations at once. The cascades described in an earlier chapter submit orders in waves, and each wave fills at a worse price.
- Concentration. A single very large position can create a deficit bigger than the whole fund.
Exchanges also differ in how much of the fund they publish and how large it is relative to open interest. A fund that looks large in absolute terms can still be small compared with the leveraged exposure it backs.
How ADL picks its targets
ADL needs a counterparty for the bankrupt position. If a long is bankrupt, the exchange must close the equivalent amount of shorts, and the reverse for a bankrupt short. It chooses from the opposite side, and only from positions that are in profit.
Most exchanges rank candidates by a score that combines profit and leverage. A common form is:
score = profit percentage × effective leverage
- Profit percentage is unrealized profit divided by the position's margin.
- Effective leverage is position value divided by margin plus unrealized profit.
A highly leveraged trader sitting on a large gain scores highest. This is intentional. Such a trader is the most likely to have been on the other side of the failed position, and the one whose gain depends most on the lost trader's margin. Venues publish this ranking as an indicator, often a row of five lights, so you can see how close you are to the front of the queue.
Selected positions are closed at the bankruptcy price of the failed position, not at the current mark price. If the failed long's bankruptcy price is 90 and the market is at 89, a short selected by ADL is closed at 90. That price is worse than the 89 the short could otherwise have realized, but it is still a profit if the short was opened at 100.
A worked ranking
The code below scores four shorts and allocates ADL against a bankrupt long of size 15. The mark price is 89. Exchange formulas differ in detail, so treat this as a model of the logic, not any one venue's rule.
def adl_score(side, entry, mark, size, margin):
"""Score = profit % of margin * effective leverage. Unprofitable positions score 0."""
pnl = (mark - entry) * size if side == "long" else (entry - mark) * size
if pnl <= 0:
return 0.0
profit_pct = pnl / margin
effective_leverage = mark * size / (margin + pnl)
return profit_pct * effective_leverage
def allocate_adl(bankrupt_size, candidates, mark):
"""Close ranked profitable candidates until the bankrupt size is matched."""
scored = []
for p in candidates:
score = adl_score(p["side"], p["entry"], mark, p["size"], p["margin"])
if score > 0:
scored.append((score, p))
scored.sort(key=lambda item: item[0], reverse=True)
remaining = bankrupt_size
fills = []
for score, p in scored:
if remaining <= 0:
break
closed = min(remaining, p["size"])
fills.append((p["name"], round(score, 2), closed))
remaining -= closed
return fills, remaining
shorts = [
{"name": "A", "side": "short", "entry": 100.0, "size": 10.0, "margin": 100.0}, # 10x
{"name": "B", "side": "short", "entry": 100.0, "size": 10.0, "margin": 500.0}, # 2x
{"name": "C", "side": "short", "entry": 95.0, "size": 10.0, "margin": 95.0}, # 10x
{"name": "D", "side": "short", "entry": 85.0, "size": 10.0, "margin": 85.0}, # losing
]
fills, unmatched = allocate_adl(15.0, shorts, 89.0)
print(fills, unmatched)
# [('A', 4.66, 10.0), ('C', 3.63, 5.0)] 0.0Short A has the highest score because it combines a 110% return on margin with high effective leverage. It is closed in full. Short C is closed in part. Short B has the same dollar profit as A, but it posted five times the margin, so its score is 0.32 and it is untouched. Short D is losing money and is never eligible.
What it looks like to the trader
If you are selected, you see your position reduced or closed at a price you did not choose. The trade appears in your history with a label such as "auto-deleveraging". You keep the profit you had at the ADL price, and the money is not lost. What you lose is the position, and with it any further gain if the move continued. You also take on re-entry risk, because the market is probably moving violently at that moment.
For hedged traders the effect can be worse. Take a trader who is long spot and short a perpetual as a hedge. If ADL closes the short while spot is still held, the hedge disappears and the trader is left with a naked long into a falling market.
Edge cases and design differences
- ADL is rare. On most days it never happens. It appears in extreme moves where liquidation deficits exceed the fund, and the same stress usually also widens spreads and thins order books.
- Cross margin can lower ADL risk for the failed account. In cross margin, other equity in the account absorbs losses before bankruptcy, so fewer deficits arise. The trade-off is that the same account can lose more than a single position's margin.
- Socialized loss is the alternative. Some venues spread a deficit across all winning traders as a small haircut on profits instead of closing positions. This keeps positions open but reduces everyone's payout, and it is harder to predict.
- Partial ADL is possible. Only as much of a selected position is closed as the deficit needs, as short C shows above.
- Rules are published but vary. The score formula, the ranking display, and how the fund is topped up differ by exchange. Check the specific documentation for any venue you use.
- DeFi lending works differently. Protocols such as lending markets have no ADL. If liquidators cannot repay bad debt, the protocol records it as a shortfall. It is then covered by a reserve, by token holders, or by losses to depositors.
Reducing your exposure to ADL
You cannot opt out of ADL on a venue that uses it, but you can lower the odds and the damage:
- Check the ADL indicator on profitable positions during volatile periods. Reduce size voluntarily if you are near the front of the queue.
- Lower leverage on winning positions by taking some profit or adding margin. Both reduce effective leverage and therefore the score.
- Do not rely on a single venue for a hedge. A hedge that can be closed against your will is only partly a hedge.
- Prefer venues that publish the size of the insurance fund relative to open interest and explain their ADL rules in plain terms.
Exercise
A bankrupt long of size 20 must be matched. Two shorts are eligible at mark price 100. Short X: entry 110, size 15, margin 165. Short Y: entry 120, size 15, margin 450. Using the chapter's score (profit % of margin × effective leverage), which short is closed first, and how much of the other is closed?
Show answer
Short X: pnl = (110 − 100) × 15 = 150; profit % = 150 / 165 ≈ 0.909; effective leverage = 100 × 15 / (165 + 150) = 1500 / 315 ≈ 4.76; score ≈ 4.33. Short Y: pnl = (120 − 100) × 15 = 300; profit % = 300 / 450 ≈ 0.667; effective leverage = 1500 / (450 + 300) = 2.0; score ≈ 1.33. X ranks first, so it is closed in full (15). The remaining 5 units are taken from Y, which is closed in part.
Exercise
Why does ADL close positions at the failed position's bankruptcy price rather than at the current mark price?
Show answer
The exchange needs the counterparty trade to net the failed position's losses to exactly zero. At the bankruptcy price the failed account's equity is zero, so the matched profitable trader receives what the failed trader owed, with no additional deficit created. Using a worse market price would reintroduce a loss that nobody had covered.