# Liquidation Logic

### **Liquidation Criteria**

When a trading account’s equity falls below the maintenance margin requirement, or when the Margin Ratio exceeds 100%, the account becomes subject to liquidation.

The Margin Ratio is calculated as the sum of maintenance margin requirements for all open positions divided by Equity, multiplied by 100%, where:

* Maintenance Margin Requirement (per position) = Abs(Position Size × Mark Price) × Maintenance Margin Rate
* Equity = USDC Balance + Spot Equity + Unrealised PnL

Before liquidation occurs, Extended issues two margin calls:

* First margin call: when the Margin Ratio exceeds 66%
* Second margin call: when the Margin Ratio exceeds 80%

Margin calls do not impose any restrictions on the account and serve only as warnings that the account is approaching liquidation. To avoid liquidation, users should either add collateral or reduce their positions.

### Liquidation Process

The overall liquidation process works as follows:

1. **Liquidate XVS (first partial and then full)**
   1. Liquidate XVS in up to 5 steps, each comprising 20% of the original XVS balance (with a minimum liquidation value of $1,000).
   2. Refer to the details of XVS liquidation [here](/extended-resources/vault.md).
2. **Liquidate perpetual positions (first partial and then full)**
   1. If the account remains in liquidation after the XVS balance has been liquidated, the system identifies the perpetual position with the largest unrealised loss.
   2. Gradually liquidate this position using up to five Fill-or-Kill orders, each comprising 20% of the position’s original size (with a minimum order value of $1,000), executed at the position’s Bankruptcy Price.
   3. If any of the partial liquidation orders fail, a single Fill-or-Kill order is executed for the entire position size at a price 5% worse than the Bankruptcy Price.
   4. If the account remains in liquidation, the system proceeds to the position with the next largest unrealised loss and repeats the process.
3. **Liquidate spot (first partial and then full)**
   1. If the account remains in liquidation after all perpetual positions have been closed, the system identifies the spot asset with the lowest contribution to equity. Refer to contribution factors of spot assets [here](/extended-resources/trading/unified-margin-and-balances.md#collateral-assets).
   2. The same liquidation process as for perpetual positions is then applied, with the user’s spot holdings liquidated via [spot order books](https://api.docs.extended.exchange/#spot-trading).
4. **Deleverage perpetual positions**
   1. If account equity falls below zero and a perpetual position cannot be liquidated through the order book at an acceptable price, the Auto-Deleveraging (ADL) process is initiated.
   2. During ADL, the liquidated position is closed against the most profitable trader with the highest leverage, as determined by the ADL ranking at the [Bankruptcy Price](#liquidation-and-bankruptcy-prices) of the Liquidated Position.
   3. The ADL ranking is computed separately for long and short positions.
      1. For Profitable Position: ADL Ranking = PNL Percentage × Position Margin Ratio
      2. For Loss Making Position: ADL Ranking = PNL Percentage ÷ Position Margin Ratio, where:&#x20;
   4. PnL Percentage and Position Margin Ration in the formula above are calculated as follows:
      1. PNL percentage = Unrealised Position PnL ÷ Abs(Position Size × Entry Price)
      2. Position Margin Ratio = Abs (Position Size × Mark Price) × Maintenance Margin Rate ÷ Max(Equity,1).
   5. If a profitable user is selected for ADL in, their open orders in that market are canceled, while open orders for other markets remain unaffected.&#x20;
   6. Trading and liquidation fees are not charged in ADL.
5. **Transfer spot to the vault**
   1. If a liquidated account becomes insolvent (Equity < 0), holds no perpetual positions, and spot liquidation via the order book fails, the system transfers the user’s spot balances to the vault, the protocol’s primary lender, in exchange for USDC.
   2. The transfer occurs at the Bankruptcy Price, i.e. the theoretical price at which the user’s equity after the trade would be exactly zero.
   3. In this scenario, the vault captures the haircut applied to the spot asset. For example:
      1. The liquidated user is insolvent (Equity < 0)
      2. User spot holdings: 0.1 BTC (index price: $100,000), equity contribution $9,000
      3. User USDC balance: −$9,100
      4. The vault pays $9,100 USDC and receives 0.1 BTC worth $10,000, capturing $900 as profit.
   4. Once a spot asset is transferred to the vault, it is sold via the order book using a Dutch auction mechanism, with the discount gradually increasing from 0% up to the maximum haircut (e.g. 10%).
   5. If the discount reaches the haircut level and the position remains unfilled, or if only partial fills are observed during the process, the vault pauses for 1 minute and then restarts the auction from a 0% discount.
6. **Deleverage spot**
   1. If spot liquidation via the order book fails and the vault’s USDC balance is fully depleted (i.e. all vault equity is held in non-USDC assets), a last-resort mechanism, Spot ADL, is triggered.
   2. Under Spot ADL, losses from insolvent accounts (Equity < 0, where the negative USDC balance exceeds the equity contribution of other spot assets) are socialised across USDC depositors.
   3. In this process, the spot balances of the insolvent account(s) are exchanged for the USDC balances of deleveragers at the Bankruptcy Price of the insolvent account. As a result:
      1. The insolvent account is brought to zero
      2. Deleveragers exchange USDC for the spot balances of the deleveraged account(s) at a profit, capturing the haircut applied to spot assets.
   4. In practice, this scenario is highly unlikely, as both soft controls (interest rates on USDC borrowings) and hard controls (limits on maximum deposits of non-USDC assets) are designed to prevent the system from reaching the Spot ADL stage.

**Key principles of the liquidation process:**

1. To safeguard users’ margin and minimise potential losses, Extended applies partial liquidation throughout the process, aiming to avoid fully closing user's exposure whenever possible
2. The liquidation process stops as soon as the account’s Margin Ratio becomes ≤ 100%
3. If a position is liquidated at a price better than its Bankruptcy Price, a 1% liquidation fee is paid to the Extended Vault
4. If a position is liquidated at a price worse than its Bankruptcy Price, losses are absorbed by the Extended but only within the risk limits described below.
5. All liquidations are deterministic, and the vault knows its PnL for every liquidation trade, as it closes the liquidated position before taking it over.
6. If the vault cannot close a position at an acceptable price within the defined risk limits, it does not take over the position, and the position is instead auto-deleveraged (ADL)
7. Auto-Deleveraging (ADL) is triggered if a perpetual position or spot asset cannot be liquidated within 5% of the Bankruptcy Price, or if the insurance fund is unable to cover the losses

### Insurance Fund

The Extended Vault serves as a shared insurance fund across all markets, but access to it and the maximum loss it can absorb per trade depend on the specific market group. Refer to the section [Trading Rules](/extended-resources/trading/trading-rules.md) for grouping of crypto markets.

<table><thead><tr><th width="119.875">Group*</th><th width="300.46875">Access to % of the Fund in given 24H</th><th>Max Loss by the Fund per Trade</th></tr></thead><tbody><tr><td>Perpetual Group 1</td><td>2.5%</td><td>$100k</td></tr><tr><td>Perpetual Groups 2-4</td><td>1.25%</td><td>$50k</td></tr><tr><td>Perpetual Group 5</td><td>1.25%</td><td>$25k</td></tr><tr><td>Perpetual Group 6</td><td>1.25%</td><td>$15k</td></tr><tr><td>Perpetual Group 7</td><td>0.25%</td><td>$5k</td></tr><tr><td>Perpetuals on TradFi markets</td><td>1.25%</td><td>$50k for FX and XAU, $25k for the rest</td></tr><tr><td>wBTC, ETH and USDT Spot</td><td>5%</td><td>$100k</td></tr><tr><td>EURC Spot</td><td>5%</td><td>$50k</td></tr></tbody></table>

Remaining Insurance Fund Limit for a given market = Daily Insurance Fund Limit - Insurance Fund Loss on a given market during this day.

Besides market-level usage limits, the insurance fund is also subject to a global constraint: it cannot be depleted by more than 5% in a single day.

Daily Insurance Fund Limits are updates once a day at 00:00 UTC.

### Liquidation and Bankruptcy Prices

The Liquidation Price is the Mark Price of a perpetual position at which the account’s Margin Ratio exceeds 100%, indicating that the liquidation process should begin.

It is important to note that the Liquidation Price is a reference value. Actual liquidation occurs only when the Margin Ratio exceeds 100%.

Liquidation Price (Position A) = (Maintenance Margin of Other Positions − USDC Balance − Spot Equity − Unrealised PnL of Other Positions + Position A Size × Position A Entry Price) ÷ Position A Size, where:

* USDC Balance = Deposits − Withdrawals + Realised PnL
* Spot Equity = sum of (Spot Balance × Index Price × Contribution Factor) across all assets
* Unrealised PnL = Position Size × (Mark Price − Entry Price)
* Position Size is positive for long positions and negative for short positions

The Bankruptcy Price is the price at which liquidation orders are submitted and Auto-Deleveraging (ADL) is performed.

It represents the price at which, if the position is liquidated, the account’s Margin Ratio remains unchanged.

Bankruptcy Price of Perpetual Positions (Position A) = (Maintenance Margin of Other Positions ÷ Margin Ratio − USDC Balance − Spot Equity − Unrealised PnL of Other Positions + Position A Size × Position A Entry Price) ÷ Position A Size

Bankruptcy Price of Spot Assets (Asset A) = (Maintenance Margin ÷ Margin Ratio − USDC Balance − Spot Equity of Other Assets − Unrealised PnL) ÷ Asset A Size


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.extended.exchange/extended-resources/trading/liquidation-logic.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
