Skip to main content

Why Simulate Liquidation?

A leveraged backtest without liquidation simulation is fiction. A 10× leveraged position can be liquidated by a 10% adverse move — but without liquidation modeling, the backtest simply holds through the drawdown and recovers. This produces impossibly good results. ClyptQ simulates liquidation per exchange with the correct maintenance margin rate (MMR), liquidation fee, and margin ratio formula for each venue.

How Liquidation Works

The Check

After every tick, for every futures account with open positions, ClyptQ checks whether the account should be liquidated:

Two Margin Ratio Formulas

Exchanges use one of two formulas to compute margin ratio: Inverted (Binance):
When equity falls below maintenance margin, the ratio exceeds 100% and liquidation triggers. Normal (Bybit, Gateio, Kraken, Coinbase):
When equity falls below maintenance margin, the ratio drops below 1.0 and liquidation triggers. Both formulas express the same economic condition — equity insufficient to cover margin requirements — but the numbers and threshold directions differ.

Exchange-Specific Parameters

The Default MMR values are Tier 1 (smallest position) rates. In reality, exchanges use tiered MMR where larger positions require higher maintenance margin. ClyptQ supports dynamic tier resolution for exchanges that expose tier data via CCXT: Binance (requires API key), Bybit, Gateio, and Kraken fetch real-time tier brackets. Coinbase does not expose tier data — it always uses the static default (6.67%).

Liquidation Calculation Step by Step

Example: Binance Futures (Inverted Formula)

All positions are closed at market price, liquidation fee is deducted, and the account’s remaining equity (if any) is the post-liquidation balance.

Example: Bybit Futures (Normal Formula)

Example: Gateio (Higher Threshold)

Gateio uses a 1.5 threshold instead of 1.0 — meaning liquidation triggers earlier than on other exchanges:
This is why exchange-specific simulation matters — the same position can be liquidated on one exchange and safe on another.

What Happens at Liquidation

When liquidation triggers:
  1. All positions in the account are closed at current market price (with slippage applied)
  2. Liquidation fee is deducted from equity
  3. ExecutionResult is created with trigger_type: "liquidation" metadata
  4. Console warning is printed: ⚠️ [LIQUIDATION] binance:futures: 2 positions liquidated
  5. Remaining equity (if positive) stays as cash in the account
The ExecutionResult includes full audit data:

Cross vs Isolated Margin

Cross Margin (Default)

All positions in an account share the same margin pool. The entire account balance is used as collateral:
A loss on Position A is offset by the full account balance, including unrealized gains on Position B.

Isolated Margin

Each position has its own margin allocation. Losses on one position cannot consume margin from another:
ClyptQ’s current backtest uses cross margin by default (all positions share the account balance). Isolated margin simulation is planned for a future release.

Configuration

Default Behavior

No configuration needed. Liquidation is checked automatically for every futures account after each tick:

Custom MMR Override

For tiered positions or custom risk parameters:

Impact on Strategy Design

Leverage Selection

Higher leverage means less equity buffer before liquidation: Without liquidation simulation, a 10× backtest survives a 50% drawdown and “recovers.” With simulation, it gets liquidated at ~8% and the equity goes to near zero.

Stop Loss as Liquidation Prevention

Using stop-loss orders prevents liquidation and preserves capital:
ClyptQ’s TP/SL simulation works together with liquidation — if the stop-loss doesn’t trigger (e.g., gap down), liquidation still fires as a backstop.

Exchange Specifics

Full exchange parameter tables including margin tiers

Cost Models

Fee structures that interact with liquidation costs