Liquidations
GX Exchange uses a progressive liquidation system designed to minimize user losses while protecting the exchange from systemic risk. The system employs partial liquidation with cooldown periods, full liquidation as a backstop, and an insurance fund to absorb residual losses.
Liquidation Trigger
A position is eligible for liquidation when the account’s equity falls below its total maintenance margin requirement:
if equity < sum(maintenance_margin for all positions):
trigger liquidationEquity is calculated as:
equity = collateral + sum(unrealized_pnl for all positions)Partial Liquidation
For positions with notional value exceeding $100,000, the system uses partial liquidation to give traders a chance to add margin or for the market to recover:
Step 1: Initial Partial Liquidation (20%)
- The system liquidates 20% of the undercollateralized position as a market order
- The remaining 80% of the position is preserved
- A 30-second cooldown begins
partial_size = position_size * 2,000 / 10,000 // 20% = 2000 bps
partial_size = max(partial_size, 1) // at least 1 unitStep 2: Cooldown Period
- During the 30-second cooldown, the account is monitored but not further liquidated
- This window allows the trader to deposit additional margin or for price recovery
- If the account returns to a safe margin ratio during cooldown, no further action is taken
Step 3: Backstop (Full Liquidation)
- If the account is still undercollateralized when checked during the cooldown window, the entire remaining position is liquidated immediately
- After the cooldown expires, if the account is still undercollateralized, another 20% partial liquidation cycle begins
Small Position Liquidation
Positions with notional value at or below $100,000 are liquidated in full immediately. Partial liquidation on small positions would create excessive overhead for minimal benefit.
Liquidation Price
All liquidation fills execute at the current mark price. The mark price (median of oracle + EMA, book median, and external perp median) ensures fair execution even during volatile conditions.
Insurance Fund
The insurance fund serves as the counterparty of last resort:
- When a position is liquidated, realized PnL is applied to the account’s collateral
- If the account’s collateral goes negative after liquidation (bankrupt), the insurance fund absorbs the deficit
- The insurance fund is replenished by trading fees
if account.collateral < 0 after liquidation:
insurance_fund += account.collateral // negative value reduces fund
account.collateral = 0 // reset to zeroPost-Liquidation: ADL
If the insurance fund is depleted and an account remains bankrupt, the system triggers Auto-Deleveraging (ADL) to close the position against profitable counterparties. See Auto-Deleveraging.
Liquidation Flow Summary
Account falls below maintenance margin
|
v
Position notional > $100K?
| |
YES NO
| |
v v
Liquidate 20% Liquidate 100%
| |
v v
30s cooldown Apply PnL to collateral
| |
v v
Still under- Bankrupt?
collateralized? |
| YES -> Insurance fund absorbs
YES |
| NO -> Done
v
Full liquidation
|
v
Bankrupt? -> Insurance fund -> ADL if fund depletedCooldown Tracking
The liquidation engine maintains a per-position cooldown tracker keyed by (account, market). Cooldown records are periodically cleaned up to prevent unbounded state growth.