# Margining

Meridian calculates margin separately for each quote-token pool in a subaccount. The product API returns the applicable mode in `marginMode`.

## Cross Margin

Products with `marginMode: "CROSS"` share the same concrete USD quote-token pool. Balance and risk are shared across all positions in that pool.

PnL and maintenance margin are shared across positions in the pool. Liquidation applies to the full pool.

## Isolated Margin

Products with `marginMode: "ISOLATED"` use a synthetic quote token backed by the exchange USD token. Each quote token forms a separate margin pool. mPerps use this mode.

Collateral converts 1:1 between the USD token and the isolated quote token. Isolated quote tokens are not directly depositable or withdrawable.

## Initial Margin

Initial margin is the minimum collateral for new positions and new orders. Leverage is set per product, not per position.

* `openMarketInitialMargin` applies during normal trading.
* `closedMarketInitialMargin` applies to new exposure during an mPerp [mark-price gap](/trading/perpetual-futures/rwa-perpetuals#reference-market-schedules).

<MathBlock tex={String.raw`\text{initial margin} = \text{position notional} \times \text{initial margin fraction}`} />

Maximum leverage for new exposure is `1 / initial margin fraction`. For example, `openMarketInitialMargin: "0.02"` allows 50x.

## Maintenance Margin

Maintenance margin is the minimum equity that a margin pool must keep. The API returns it as `maintenanceMargin`. It does not change during a mark-price gap.

The liquidation check also includes the product taker fee and precision tolerances.

If pool equity falls below the total maintenance-margin requirement, the pool is eligible for liquidation.

## Equity

At a high level, margin-pool equity includes:

```text
equity = balance + unrealized PnL - unpaid funding - unpaid position fees
```

The sign of a funding amount depends on the position side and the funding rate. Trading fees and realized PnL are already part of balance after settlement.

## Available Margin

Available margin is the amount that can support a new order or a withdrawal. Meridian uses a conservative calculation:

* Unrealized losses reduce available margin.
* Unrealized gains do not increase available margin for new risk.
* Open orders reserve margin.
* Outstanding funding and position fees reduce available margin.

Closing a position can release margin. Canceling an unfilled order can release its reserve.

The displayed liquidation price is an estimate. Balance, positions, orders, funding, position fees, and product settings can change it.

Use `GET /v1/product` for `marginMode`, `maintenanceMargin`, `openMarketInitialMargin`, and `closedMarketInitialMargin`. Use `GET /v1/subaccount/balance` for `amount`, `available`, and `totalUsed`.

`maxLeverage` is an onchain safety bound. Use the margin fields above, not `maxLeverage`, to size positions and orders.
