How Does a Liquidation Engine Work in Perpetual Swaps?

in

How Does a Liquidation Engine Work in Perpetual Swaps?

⏱ 6 min read

Table of Contents

💡
Ready to Trade with AI?
Join thousands trading smarter on Aivora — the AI-powered crypto exchange. Spot trading, futures, and AI-driven market predictions.
Open Free Account →
  1. What Is a Liquidation Engine in Perpetual Swaps?
  2. How Does the Liquidation Engine Trigger a Position Close?
  3. Why Does the Liquidation Engine Use a Mark Price?
  4. What Happens When the Engine Can’t Fully Liquidate?
Key Takeaways:

  1. The liquidation engine uses a mark price—not the last traded price—to prevent unfair liquidations from short-term volatility spikes.
  2. Partial liquidation is a common feature that reduces a trader’s position size instead of closing the whole thing, giving them a chance to recover.
  3. Insurance funds and auto-deleveraging are the two safety nets that protect solvent traders when a liquidation can’t be filled on the order book.

Over $100 million in long positions got wiped out in a single hour last March when Bitcoin dropped 8%. Sound familiar? That wasn’t just market movement—it was the perpetual swap liquidation engine doing its job. Most traders know it as the thing that takes their collateral, but few understand how it actually decides who gets liquidated, when, and why. Let’s break it down.

What Is a Liquidation Engine in Perpetual Swaps?

A liquidation engine is an automated risk management system built into every perpetual swap exchange. Its job is simple: monitor all open positions in real time and close any position that falls below the maintenance margin requirement. Think of it as the exchange’s circuit breaker. Without it, a single over-leveraged trader could default and leave the exchange—and other traders—holding the bag.

The engine runs on every tick of the order book. It checks each account’s margin ratio, which is calculated as (wallet balance + unrealized PnL) / position notional. If that ratio drops below the maintenance margin threshold—typically 0.5% to 2% depending on leverage—the engine flags the position. And it doesn’t wait. It acts within milliseconds.

But here’s the kicker: the engine doesn’t just look at the last price. It uses a mark price, which is an average of multiple price feeds from major spot exchanges. This prevents a single flash crash on Binance from liquidating everyone who bought the dip. For more on how exchanges calculate these prices, check out Investopedia’s guide to mark-to-market.

How Does the Liquidation Engine Trigger a Position Close?

Once the engine detects a margin ratio below maintenance, it doesn’t just delete the position. It sends a market order to the order book to close the trade. The idea is to exit the position as fast as possible to prevent further losses that could exceed the trader’s collateral.

Here’s the step-by-step process:

  • Detection: Engine calculates margin ratio at each price update. If ratio ≤ maintenance margin, the position enters liquidation queue.
  • Bankruptcy price: Engine calculates the price at which the trader’s collateral would hit zero. This is the “bankruptcy price.”
  • Market order: Engine submits a market order to close the position. For a long, it sells. For a short, it buys.
  • Fill priority: The liquidation order gets top priority on the order book, often bypassing the regular queue.

But here’s the part that trips up most traders: the engine uses a partial liquidation system on most modern exchanges. Instead of closing the entire position, it reduces the position size just enough to bring the margin ratio back above maintenance. So if you’re in a $10,000 long with 50x leverage and the price dips, the engine might close only $2,000 worth. You keep the remaining $8,000 position. That’s a lifeline most people don’t realize exists.

And the engine doesn’t stop there. It recalculates the margin ratio after each partial fill. If the price keeps moving against you, it’ll keep chipping away until either the price reverses or your position is gone.

Why Does the Liquidation Engine Use a Mark Price?

This is the single biggest point of confusion for new perpetual traders. Why doesn’t the engine use the last traded price? Because the last price is volatile. A single large sell order can push the last price down 3% in a second, but the real market value hasn’t changed that much. Using the last price would cause unfair liquidations during short-term wicks.

The mark price is calculated using a funding rate-adjusted index from multiple spot exchanges. For example, the BTCUSDT perpetual mark price might be the median of prices from Binance Spot, Coinbase, Kraken, and OKX. This smooths out anomalies. So even if someone dumps 500 BTC on Binance and the last price drops to $60,000, the mark price might only drop to $61,500. That difference can save a trader’s position.

Exchanges also use the mark price to calculate unrealized PnL for margin purposes. That means your liquidation price is based on the mark price, not the last price. But here’s the catch: once the engine triggers a liquidation, it uses the last price to execute the market order. So the mark price protects you from getting liquidated, but the last price determines how much you lose when the engine actually closes the trade.

If you want to understand how different exchanges handle this, check out .

What Happens When the Engine Can’t Fully Liquidate?

This is the nightmare scenario. The engine sends a market order to close a position, but there isn’t enough liquidity on the order book to fill it at a price that covers the trader’s debt. This happens during extreme volatility—think 10-20% flash crashes. The position gets filled at prices far below the bankruptcy price, and the trader’s collateral isn’t enough to cover the loss.

So who eats the loss? The exchange has two safety nets:

  • Insurance fund: A pool of money collected from liquidation fees and a portion of the funding rate. When a position can’t be fully covered, the insurance fund pays the difference. This protects profitable traders from being negatively impacted by the bad debt.
  • Auto-deleveraging (ADL): If the insurance fund runs out, the exchange automatically reduces positions of profitable traders in the opposite direction. So if a long position gets liquidated and the fund is empty, profitable short traders get their positions partially closed at the bankruptcy price. This is rare but happens during major black swan events.

Most exchanges rank ADL by profitability. Traders with the highest unrealized profit get deleveraged first. That’s why you’ll sometimes see warnings about “ADL rank” in your position details. It’s a direct measure of how likely you are to get your position force-closed if the insurance fund fails.

A real-world example: during the May 2021 crypto crash, several exchanges saw insurance funds drain within minutes. BitMEX’s insurance fund took a $300 million hit, but still covered all liquidations without triggering ADL. That’s rare. Most smaller exchanges would have triggered ADL in a similar scenario.

FAQ

Q: Can I avoid liquidation by adding more margin after the engine flags my position?

A: Yes, but only if you act before the engine executes the market order. Once your margin ratio drops below maintenance, the engine typically triggers within milliseconds. Some exchanges offer a “margin call” warning that gives you a few seconds to add collateral, but this isn’t guaranteed. If you’re on 100x leverage, the window is essentially zero.

Q: Does the liquidation engine close my entire position or just part of it?

A: Most modern exchanges use partial liquidation. The engine closes only enough of the position to bring your margin ratio back above the maintenance threshold. For example, if you have a $20,000 position and the price drops 2%, the engine might close $4,000 worth. You keep the remaining $16,000 position with a healthier margin ratio.

Q: What’s the difference between liquidation price and bankruptcy price?

A: The liquidation price is the mark price at which your margin ratio hits the maintenance level. The bankruptcy price is the price at which your collateral would be completely wiped out. When the engine liquidates your position, it aims to fill at a price between the two. If it fills below the bankruptcy price, the insurance fund covers the gap.

Final Thoughts

Let’s recap the key points:

  • The liquidation engine uses a mark price to prevent unfair liquidations from short-term price spikes.
  • Partial liquidation can save part of your position instead of closing everything at once.
  • Insurance funds and ADL protect the exchange and solvent traders when liquidations exceed collateral.

Understanding the engine’s logic gives you an edge. You can calculate your real liquidation price, know when partial liquidation kicks in, and avoid over-leveraging during low-liquidity hours. Want to track these mechanics in real time without staring at charts all day? Check out Aivora AI Trading signals for automated alerts that factor in liquidation engine behavior.

🚀
Trade Smarter with AI
AI-powered crypto exchange — BTC, ETH, SOL & more
Start Trading →
M
Maria Santos
Crypto Journalist
Reporting on regulatory developments and institutional adoption of digital assets.
TwitterLinkedIn

Related Articles

How Does Perpetual Contract Funding Rate Work
Jun 29, 2026
Automated Funding Rate Trading Bot Setup
Jun 28, 2026
How to Calculate Required Margin for Short Position
Jun 27, 2026

About Us

Exploring the future of finance through comprehensive blockchain and Web3 coverage.

Trending Topics

MiningBitcoinMetaverseLayer 2StablecoinsAltcoinsStakingDAO

Newsletter

BTC: ... ETH: ... SOL: ...