# 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 exposure. The product's maximum leverage sets its minimum initial-margin fraction.

<MathBlock tex={String.raw`\text{initial margin fraction} = \frac{1}{\text{maximum leverage}}`} />

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

The exchange can reserve additional margin for open orders. The exact requirement depends on the current positions and orders in the margin pool.

## Maintenance Margin

Maintenance margin is the minimum equity that a margin pool must keep. Meridian derives the base maintenance-margin fraction from maximum leverage.

<MathBlock tex={String.raw`\text{base maintenance margin fraction} = \frac{1}{2 \times \text{maximum leverage}}`} />

The onchain liquidation check also includes the product taker fee and precision tolerances. Maximum leverage alone does not define the exact liquidation threshold.

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 `maxLeverage` and `marginMode`. Use `GET /v1/subaccount/balance` for `amount`, `available`, and `totalUsed`.
