> ## Documentation Index
> Fetch the complete documentation index at: https://docs.perpetradex.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Risk Engine

> Where every trade gets checked against Perpetra's risk limits

Every position on Perpetra passes through the same central set of checks, whether it's being opened for the first time, added to, or evaluated for liquidation. That's what the risk engine does: it's the single place that decides whether a trade is currently allowed, and whether an existing position is still healthy.

## Checks before a trade goes through

```mermaid theme={null}
flowchart TD
    A[Trade requested:\nopen or increase] --> B{Enough collateral\nposted for the\nrequired margin?}
    B -- No --> R[Rejected]
    B -- Yes --> C{Leverage within\nthe market's\nallowed range?}
    C -- No --> R
    C -- Yes --> D{Position size within\nthe market's max?}
    D -- No --> R
    D -- Yes --> E{Market-wide open\ninterest cap\nstill has room?}
    E -- No --> R
    E -- Yes --> F[Trade approved]
```

These checks are independent of each other, passing one doesn't excuse you from the others. A trade needs enough collateral posted relative to its size, has to sit within the market's allowed leverage range (both a minimum and a maximum), can't exceed the market's maximum position size, and can't push the market's total long or short exposure past its configured cap. Long and short open interest are tracked and capped separately, so one side filling up doesn't block the other.

## Checking position health

Once a position is open, the risk engine is also what determines whether it's still healthy or has become eligible for liquidation. That calculation, and exactly how a margin ratio and liquidation price are derived, is covered in full in [PnL & Liquidation](/pnl-and-liquidation).

## Isolated vs. cross

How health is evaluated depends on the position's margin mode:

* **Isolated positions** are checked individually, their own collateral against their own risk.
* **Cross positions** are checked as a whole account, total equity across every cross position against the combined maintenance requirement of all of them together.

The mechanics of that difference are covered in [Margin Modes](/margin-modes).

## Why this is centralized

Keeping every limit and every health check in one place means the same rules apply no matter which part of the platform is asking, opening a trade, adding to a position, or a keeper checking whether something is liquidatable all go through the same logic rather than each having their own separate version of these rules.
