> For the complete documentation index, see [llms.txt](https://docs.hello.trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hello.trade/about/trading/liquidation.md).

# Liquidation

## Overview

Liquidation occurs when an account's margin ratio falls below the maintenance margin requirement. The system automatically closes positions to prevent negative equity and protect users.

Liquidation is evaluated **per margin scope**: cross positions are assessed together against the shared collateral pool, while an isolated position is assessed against only the margin dedicated to it — an isolated liquidation cannot touch cross collateral or any other position's isolated margin.

All liquidation calculations use **mark price** to ensure fair and manipulation-resistant valuations.

***

## Margin Requirements

### Opening Margin

Minimum margin required to open a position:

```
Opening Margin = Position Notional / Leverage
```

Opening margin ensures traders have sufficient capital to support new positions.

### Maintenance Margin

Minimum margin required to maintain open positions:

```
Maintenance Margin = |Position Size| × Mark Price / (2 × Max Leverage)
```

With 10x maximum leverage, maintenance margin = 5% of position notional value.

**Example:**

* Position: 100 NVDA at $500 mark price
* Position Notional: 100 × $500 = $50,000
* Max Leverage: 10x
* Maintenance Margin: $50,000 / (2 × 10) = $2,500 (5%)

## Liquidation Price

The liquidation price is the price at which an account's margin falls below the maintenance margin requirement.

### Simplified Calculation

Liquidation occurs when:

```
Account Equity < Total Maintenance Margin
```

Where:

```
Account Equity = Balance + Unrealized PnL
Unrealized PnL = Position Size × (Mark Price - Entry Price)
```

For a single position, the liquidation price can be approximated as the mark price where account equity equals maintenance margin, accounting for the entry price and current balance.

***

## Liquidation Waterfall

When an account falls below the maintenance margin requirement, positions are liquidated through a multi-step waterfall:

### 1. Order Book Liquidation

Positions are closed directly against the live order book at the best available prices.

* Minimize slippage by filling against resting limit orders
* Liquidations execute as taker orders
* Standard taker fees apply
* Orders will fill execute up until the zero-price of the positions, which is the execution price at which the account's margin ratio remains constant during liquidation.

For **LONG** positions:\
zero\_price = mark\_price × (1 - (M\_i × TAV) / MMR)

For **SHORT** positions:\
zero\_price = mark\_price × (1 + (M\_i × TAV) / MMR)

Where:

* M\_i = 1 / (2 × max\_leverage) — maintenance margin fraction
* TAV = balance + total\_unrealized\_pnl — total account value
* MMR = Σ(|size| × mark\_price × M\_i) — total maintenance margin requirement

### 2. Liquidation Auction

If order book liquidity is insufficient, the unfilled position is offered in a short on-demand auction. The gateway broadcasts the position to all subscribed trading clients, which respond with signed claims to take it over. The first claimant with sufficient margin becomes the counterparty and absorbs the position at its zero-price. If no claim is received, the position falls through to the insurance fund or ADL.

Integrators can participate via the WebSocket API — see [Liquidation Auction](/developer-tools/websocket-api/liquidation-auction.md).

### 3. Insurance Fund

If the liquidation queue cannot fully close positions before incurring bad debt, the insurance fund covers the shortfall.

**Insurance Fund Mechanics:**

* X% of Hello Vault capital is designated to the insurance fund
* Trading fees contribute to insurance fund reserves
* Insurance fund absorbs losses when liquidations cannot be filled profitably

### 4. Auto-Deleveraging (ADL)

If the insurance fund is depleted, profitable positions on the opposite side are automatically reduced to cover losses.

***

## Auto-Deleveraging (ADL)

ADL is the liquidation backstop when all other mechanisms fail.

### ADL Ranking

Accounts are ranked by **ADL score**, which prioritizes the most profitable and most leveraged positions:

```
ADL Score = PnL Ratio × Cross Effective Leverage
```

Where:

```
PnL Ratio = Raw PnL / Equity
Cross Effective Leverage = Notional / Equity
```

And:

```
Raw PnL = Position Size × (Mark Price - Entry Price)
Equity = Balance + Total Unrealized PnL
Notional = |Position Size| × Mark Price
```

**Ranking:**

1. Highest ADL scores are deleveraged first
2. Positions are reduced pro-rata within each score tier
3. ADL continues until losses are fully socialized

### ADL Notification

When ADL occurs, affected accounts receive an execution report with `messageType: "Liquidation"` indicating:

* Position reduction
* ADL execution price (bankruptcy price of the liquidated account)
* Reason: "Auto-deleveraging"

***

## Liquidation Process

### Step 1: Detection

The system performs periodic margin checks (every second):

```
Account Equity = Balance + Unrealized PnL
```

If `Account Equity < Total Maintenance Margin`, liquidation is triggered.

### Step 2: Account Freeze

Upon liquidation detection:

1. **Block account at exchange level** - Cancels all active orders, RFQs, and quotes
2. **Prevent new trading activity** - Local freeze prevents new user orders during liquidation

### Step 3: Position Closure

The liquidation engine places Limit IOC (Immediate-or-Cancel) orders to close all positions:

1. **Place Limit IOC orders** for each open position at zero-price
2. **Close via order book** at best available prices
3. **Auction unfilled portions to market makers** (if order book depth is insufficient)
4. **Invoke insurance fund** if positions cannot be filled above zero price
5. **Trigger ADL** if insurance fund is depleted

### Step 4: Post-Liquidation

After liquidation orders are placed:

* Account is unblocked at exchange level
* Local freeze is removed
* Account can resume trading once additional collateral is deposited

***

## Preventing Liquidation

To avoid liquidation:

1. **Monitor margin ratio** regularly
2. **Add collateral** when margin portfolio becomes high risk
3. **Reduce position size** to lower maintenance margin requirements
4. **Use stop-loss orders** to close positions before liquidation
