> For the complete documentation index, see [llms.txt](https://docs.coinlocally.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coinlocally.com/perpetual-contracts/overview/ladder-balancing-mechanism.md).

# Ladder Balancing Mechanism

### **What is Forced Balancing?**

The **margin rate** reflects the risk level of a user’s position. It is calculated as:

$$
\text{Margin Rate} = \frac{\text{Equity}}{\text{Position Value}}
$$

When the margin rate approaches the **minimum maintenance margin rate**, the system may intervene to **protect users and market stability** by triggering a **forced balancing**.

> ⚠️ All margin rate calculations are based on the **marked price** to avoid forced liquidation caused by illiquidity or price manipulation.

### **Ladder-Based Position Reduction**

To prevent the **market impact** and **losses** associated with fully liquidating large positions, the system employs a **laddered reduction mechanism**.

* Each **ladder tier** corresponds to a higher **maintenance margin rate**.
* If the margin rate is **insufficient** for the user’s current tier, the system will **partially reduce** the position to bring it to the next lower tier.

### **Forced Balancing Process**

Once the margin rate drops below the required threshold, the system initiates the following steps to avoid full liquidation:

1. **Cancel all open orders** for the contract.
2. **Match internal long and short positions** to reduce risk.
3. If the **margin rate is still insufficient**, the system performs **forced position reduction**:
   * The position is reduced to match the **maximum allowed size** of the next lower gear.
   * The goal is to restore a **margin rate > 0%**.

$$
\text{Positions to reduce} = P\_{\text{current}} - P\_{\text{next gear max}}
$$

4. If the user is in **the lowest gear** and the margin rate remains insufficient, the **entire position is forcibly closed**.

### **Restrictions During Forced Balancing**

During the forced reduction process:

* The user **cannot place or modify orders** related to the contract.
* In **restricted position mode**, the system will:
  * **Place a limit order** to reduce the number of contracts required.
  * Use a **price slightly better** than the current market price.
  * **Freeze the affected position direction** during the process.

### **Example (BTC Contract)**

Assume:

* User is in **Gear 3** or above: P<sub>current</sub> = 15,000
* Gear 1 max allowed position: P<sub>gear 1 max</sub> = 2,000
* Required reduction:

$$
15,000 - 2,000 = 13,000 \text{ contracts}
$$

If the system determines the user's margin rate is **less than**:

$$
\text{Maintenance Margin Rate}\_{\text{Gear 3}} + \text{Closing Fee Rate}
$$

It **will not** immediately liquidate the entire position. Instead, it initiates a **partial forced reduction** by reducing the position by two gears.

If the user is in **restricted mode**, these 13,000 contracts will be placed as limit orders at a slightly favorable price, and the position remains **frozen** until the reduction is complete.
