> For the complete documentation index, see [llms.txt](https://docs.nexus.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexus.xyz/trading/trading/perpetuals/margining.md).

# Margining

Initial and maintenance margin, leverage as a standing per-market setting, and the liquidation threshold.

The exchange engine enforces margin **natively** and checks it atomically before it accepts any order. Margining is **whole-account (cross)** today: your entire USDX balance is the collateral pool backing every open position.

### Definitions

| Term                   | Meaning                                                                            |
| ---------------------- | ---------------------------------------------------------------------------------- |
| **Notional**           | `position_size × mark_price`, the value of the position at the current mark price. |
| **Equity**             | Account balance + unrealized PnL across all positions.                             |
| **Initial margin**     | Collateral required to *open or increase* a position.                              |
| **Maintenance margin** | Minimum collateral required to *keep* a position open.                             |

### Initial margin

Initial margin is the notional scaled by the market's initial margin rate:

```
initial_margin = position_size × mark_price × initial_margin_rate
```

Equivalently, `initial_margin_rate = 1 / max_leverage`. The engine sums the initial margin required across all positions and rejects an order if your equity cannot cover it.

### Leverage

Leverage is a **standing per-market setting on your account**, not an order parameter. Set it with:

```
POST /leverage    { "market_id": "BTC-USDX-PERP", "leverage": 10 }
```

Every subsequent order in that market then requires:

```
initial_margin = position_size × mark_price / leverage
```

So raising leverage lowers the margin an order requires, and lowering it raises the margin.

**Leverage accepts any whole number from 1 up to the market's effective ceiling.** There is no fixed tier set, and the preset buttons an interface offers are its own choice on top of this range. The ceiling is:

```
max = min(max_leverage, floor(1 / initial_margin_rate))
```

The market's initial margin rate floors the margin an order can require, and therefore also caps leverage. So **a leverage selection can only make your margin requirement stricter than the market's, never looser.** At the ceiling the two formulas above agree. Read the ceiling for a market from `GET /markets/{market_id}/risk-params`.

**You do not have to set leverage before your first order.** Left unset, it behaves as the market maximum.

> **Leverage does not move your liquidation price.** The *maintenance* margin rate sets that price, and leverage does not touch it. `POST /orders/preview` reports the same projected liquidation price at any leverage. What leverage changes is how much margin a new order consumes, and therefore how much you can open.

### Maintenance margin

Each market defines its own **maintenance margin rate**. It is a configured fraction of notional, not a value derived from leverage at request time:

```
maintenance_margin = position_size × mark_price × maintenance_margin_rate
```

The maintenance margin rate is always **less than or equal to** the initial margin rate (the engine rejects any configuration where maintenance exceeds initial). A position becomes eligible for liquidation when account equity falls to **or below** the total maintenance margin across all positions:

```
liquidatable when:  equity ≤ Σ maintenance_margin
```

The threshold is **inclusive**. Equity exactly equal to maintenance liquidates. [Liquidations](/trading/trading/perpetuals/liquidations.md) derives the mark price at which that happens, so you can compute your own liquidation price.

> **Rates differ per market, and are still being tuned.** An earlier revision of this page said every market ran a flat 2% profile with `initial_margin_rate = maintenance_margin_rate`. That is no longer true: the listed markets now carry distinct rates, and maintenance is below initial on several of them. Margin rates are per-market configuration and continue to be tuned across release gates. [**Market Specifications**](/trading/trading/perpetuals/market-specifications.md) **is the authority**. It is generated from the configuration the exchange boots from, and it flags any value that is ratified but not yet deployed to the venue.

### Isolated margin

The account default margin mode can be set to cross or isolated with `POST /account/margin-mode`. The setting applies to new positions. An open position or a market's forced policy can override the account default for that market; `GET /account/margin-mode?market_id=…` returns both the default and effective mode. `POST /account/margin` adds or removes allocated margin on an open isolated position.

The [Math Engine's liquidation chapter](https://docs.nexus.xyz/math-engine/liquidation-engine) derives the isolated trigger at (L.5): a single position evaluated against its own allocated margin, with account collateral and sibling positions excluded. The account default can now be set to isolated for new positions; open positions and forced market policy still determine the effective mode where applicable.

### Worked example

This example uses `BTC-USDX-PERP`'s parameters: `initial_margin_rate = 0.02`, `maintenance_margin_rate = 0.01`. Read the current values from `GET /markets/{market_id}/risk-params` or [Market Specifications](/trading/trading/perpetuals/market-specifications.md) rather than from this example; margin rates are per-market configuration and are tuned between releases. The example opens at the market's effective ceiling from the formula above, where an order's initial margin is its notional times the initial margin rate.

You deposit **2,000 USDX**.

|                                              | Value                                                                |
| -------------------------------------------- | -------------------------------------------------------------------- |
| Largest position at the ceiling, mark 60,000 | `2,000 / (60,000 × 0.02)` = **1.666 BTC**                            |
| Margin for **1 BTC** at the ceiling          | `1 × 60,000 × 0.02` = **1,200.00**                                   |
| Margin for **1 BTC** at 10×                  | `1 × 60,000 / 10` = **6,000.00**, rejected because it exceeds equity |
| Maintenance margin on 1 BTC                  | `1 × 60,000 × 0.01` = **600.00**                                     |

The table shows two things. Leverage governs **how much you can open**. At 10× the same 2,000 USDX supports only 0.333 BTC. Maintenance margin does **not** change with your leverage selection. It is 600.00 on a 1 BTC position whether you opened it at the ceiling or at 10×, which is why your liquidation price is the same either way.

Now suppose you open **1 BTC long at 60,000** and the mark falls to **58,000**:

|                                    | Value                                   |
| ---------------------------------- | --------------------------------------- |
| Unrealized PnL                     | `1 × (58,000 − 60,000)` = **−2,000.00** |
| Equity                             | `2,000 − 2,000` = **0.00**              |
| Maintenance margin at the new mark | `1 × 58,000 × 0.01` = **580.00**        |
| `equity ≤ maintenance`?            | `0.00 ≤ 580.00` → **liquidated**        |

The account was already liquidated before the mark reached 58,000. [Liquidations](/trading/trading/perpetuals/liquidations.md) computes the exact price, 58,585.86, and walks through the close.

### Why mark price, not last price

All margin calculations use the mark price, an external index price, rather than the last trade on the book. This prevents a single thin-book trade from pushing an account into liquidation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.nexus.xyz/trading/trading/perpetuals/margining.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
