GrowBlocks
Home
Solutions
Cases
Knowledge
Design
Media

How to build a forced liquidation engine in a contract trading system

The hardest part of perpetual contract exchanges isn't matchmaking, but forced liquidation. Matching with a miswritten line of code is usable by users; forced closing with a single wrong line of code means a loss through the position. Here, we clearly explain the key design of the forced liquidation engine.

Published:2026-06-18 02:46:2910min readAuthor:GrowBlocks Team
TG:@YY462855312Website:www.grow-blocks.comShare:

1. Core issues of forced liquidation

The core of forced liquidation is "timely closing positions when users lack margin to avoid being cut into positions." It sounds simple, but the difficulty lies in three things:

  • 1.When will it trigger—How is the margin rate calculated, and where is the threshold?
  • 2.How to Level—Market orders vs. limit orders vs. takeover closing positions
  • 3.Can it still survive in extreme market conditions—What if the market has no counterparties?
合约交易系统的强平引擎怎么做

2. Margin Calculation

Real-time margin rates must be updated millisecond-level. Two mainstream models:

  • 1.Cross margin:All positions in the account share margin, flexible but risk-shared
  • 2.Isolated margin:Each position has independent margin, isolating bankruptcy but with low capital utilization

Most exchanges support it simultaneously, allowing users to choose freely.

Real-time margin calculation relies on the latest mark price. The choice of marking price directly affects the fairness of forced liquidation—using the latest transaction price of the exchange is easily triggered by malicious manipulation, and most exchanges use multi-source weighted index prices.

合约交易系统的强平引擎怎么做

3. Trigger conditions

Common designs:

  • 1.Maintenance margin rate = Position Value × Maintenance Margin Rate
  • 2.Account Equity < Maintenance margin → Forced liquidation triggered
  • 3.Tiered Margin Rates:The larger the position, the higher the maintenance margin ratio (to prevent major players from dragging down the system)
合约交易系统的强平引擎怎么做

4. Execution Priorities

Forced liquidation cannot simply be executed in the order of orders. Close out risky positions first to avoid chain liquidation. Common strategies:

  • 1.Ranked by margin rate from low to high (the most dangerous ones close first)
  • 2.Large positions are split and closed to avoid a single shock to the order book
  • 3.Record liquidation queues and process them sequentially when market conditions resume
合约交易系统的强平引擎怎么做

5. Do not be forced to enter positions in extreme market conditions

When the market crashes, competitors disappear, and forced liquidation orders cannot be held, forced liquidation losses may occur. Countermeasures:

  • 1.Automatic Reduction Mechanism (ADL):Counterparties are ranked by profit + leverage and are forced to close out part of their positions
  • 2.Insurance Fund:Accumulate fees as a risk reserve to absorb losses from losses from losses
  • 3.Gradual Liquidation:Close the worst positions first to avoid liquidating all positions at once

This mechanism sounds complicated, but in extreme market conditions, the difference is "user losses vs. platform fleeing." There are no easy shortcuts here.

合约交易系统的强平引擎怎么做
grow-blocks-logo
GrowBlocks Technical Team
Focused on custom blockchain development for 10 years, with 200+ projects delivered covering exchanges, public chains, Layer2, wallets, and DApp development. This article is based on our real project delivery experience.

Continue Reading

contact us

Want to see the complete Figma file?

Schedule a 30-minute technical consultation where we walk you through the most relevant Figma / Lanhu files for your project via remote demo, including all pages, component libraries, and interactive prototypes.