Skip to content
First Access Exchange

Margin and liquidation

Margin is dYdX's: each subaccount has a net collateral (its USDC plus the value of its positions at their oracle prices), an initial margin requirement that every trade, order and withdrawal must keep it above, and a maintenance margin requirement below which it can be liquidated. What differs is how each chain-market kind values a position and what it requires.

By market kind

KindPosition valued atInitial requirementMaintenanceLiquidated
Company perpetualn·I50% of |n|·I30% of |n|·IBoth sides, while the book is active
Binaryn·p, p the last tradeLong: n·p; short: n·(1 − p)Equal to initialNever
Putn·markLong: the premium; short: K a contractEqual to initialNever
Call, longn·markThe premiumEqual to initialNever
Call, short−n·max(mark, sale price)n·(max(mark, sale price) + X) on top of the value80% of initialBelow maintenance

X is the call margin, max(200%·S − OTM, 100%·S) a contract by default (options). Every chain market is isolated, so a subaccount's requirement is its one position's.

Orders. A long-term order on a chain market's book must be covered, together with the subaccount's other resting long-term orders on that side, as if they all filled. A short-term order is checked against margin when it matches.

Withdrawals. USDC can leave a subaccount only while what remains covers the initial requirement. For a binary, a put or a long option that means unrealized gains can't be withdrawn before resolution. For the perpetual, gains at I can, which is why the perpetual's fills are held within a band around I (company perpetuals). A subaccount holding a company perpetual that is halted or settling can't withdraw, deposit or transfer at all until it is paid.

The company perpetual

A position opened at the limit (equity 50% of notional) at index I₀ is liquidatable when the long's I < I₀ × 0.5 / 0.7 (a 28.6% fall) or the short's I > I₀ × 1.5 / 1.3 (a 15.4% rise), and bankrupt at a 50% move. While blended, I moves at most 0.5% a block. Once the company is halted nothing is liquidated or deleveraged; the position waits for settlement.

The liquidation index of an isolated perpetual subaccount, at the 30% maintenance margin, with n contracts and USDC c (unsettled funding included), is:

  • long: I = −c / (0.7·n);
  • short: I = c / (1.3·|n|).

How liquidation works

Liquidation is dYdX's engine, applied to the kinds that can be liquidated (a short call; a perpetual position on an active book):

  1. Every block each validator's liquidation daemon finds subaccounts below maintenance.
  2. The block proposer places protocol liquidation orders: immediate-or-cancel orders that close the position against the book at no worse than its fillable price, which is between the oracle price and the bankruptcy price (fillable_price_config). On a perpetual's or a call's book the limit is also held within the price band, so a liquidation fills only resting orders in the band. A short call's limit uses the calls' value at the mark, not the price the writer sold at.
  3. The liquidation fee, at most 1.5% of the notional closed (max_liquidation_fee_ppm 15,000), goes to the market's insurance fund. A loss beyond the position's collateral comes out of that fund.
  4. If the book can't take the position, it is deleveraged against positions on the other side (insurance funds and deleveraging).

Per-block limits (testnet values, /dydxprotocol/clob/liquidations_config):

LimitValue
max_liquidation_fee_ppm15,000 (1.5%)
min_position_notional_liquidated$1,000 (1,000,000,000 quote quantums)
max_position_portion_liquidated_ppm100,000 (10% of a position a block, above the minimum)
subaccount_block_limits.max_notional_liquidated$100,000 a block
subaccount_block_limits.max_quantums_insurance_lost$1,000,000 a block
fillable_price_config.bankruptcy_adjustment_ppm1,000,000
fillable_price_config.spread_to_maintenance_margin_ratio_ppm1,500,000

Liquidations show in the indexer as fills of type LIQUIDATED (the liquidated side) and LIQUIDATION (the maker), and as trades of type LIQUIDATED.