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

# Margin & liquidations

> How portfolio margin works on OCX at a high level, what triggers a liquidation, and how the insurance fund backstops the system.

OCX enforces margin **server-side**. Every order passes a margin check before it is accepted, and open positions are monitored continuously. This page explains those mechanics conceptually — the exact model parameters are internal, but the behavior you need to trade safely is described here.

## Portfolio margin

OCX uses **portfolio margin**: rather than charging margin position-by-position in isolation, it evaluates your positions together and recognizes offsetting risk. A hedged book (positions that partly cancel each other's risk) requires less margin than the same positions would if margined separately.

Two levels matter:

<CardGroup cols={2}>
  <Card title="Initial margin" icon="lock">
    The collateral required to open a position. Checked at order time — an order that would leave you under-collateralized is rejected.
  </Card>

  <Card title="Maintenance margin" icon="triangle-exclamation">
    The minimum collateral required to keep a position open. Falling below it puts the position at risk of liquidation.
  </Card>
</CardGroup>

Margin is drawn from the relevant venue bucket — `perps` for perpetuals and futures, `options` for options. Fund the bucket for the venue you trade in. See [Balances & transfers](/concepts/balances).

<Note>
  Because the margin check runs at order acceptance, a preview call (`/perps/orders/preview`) is the reliable way to see the margin required and whether an order will be approved before you send it.
</Note>

## What triggers a liquidation

Your positions carry unrealized profit and loss as the mark price moves. When adverse price movement (or accruing funding on perps) erodes your collateral so that your account can no longer meet **maintenance margin**, the position becomes eligible for liquidation.

<Steps>
  <Step title="Margin erodes">
    Losses, funding payments, or increased position risk push your account toward the maintenance-margin threshold.
  </Step>

  <Step title="Breach">
    Once maintenance margin is breached, the exchange steps in — you no longer control the timing.
  </Step>

  <Step title="Liquidation">
    The exchange closes the at-risk position to bring the account back within margin requirements.
  </Step>
</Steps>

<Warning>
  Liquidation is automatic and not guaranteed to occur at any particular price. Manage your own margin headroom proactively: watch your positions and balances, use `reduceOnly` orders to de-risk, and keep buffer above maintenance margin rather than trading at the edge.
</Warning>

You can track your risk in real time:

<CodeGroup>
  ```bash Positions theme={null}
  curl -b cookies.txt "https://<api-host>/perps/positions"
  ```

  ```bash Balances theme={null}
  curl -b cookies.txt "https://<api-host>/perps/balances"
  ```

  ```js Push updates theme={null}
  const es = new EventSource(
    "https://<api-host>/perps/stream/events?marketId=BTC-PERP",
    { withCredentials: true }
  );
  es.addEventListener("delta", e => onState(JSON.parse(e.data).payload)); // position upserts
  ```
</CodeGroup>

Perp position records include size, entry price, mark, unrealized PnL, leverage, and a **liquidation price** so you can see how much room you have.

## The insurance fund

When a liquidation cannot fully cover a position's losses, the shortfall (bad debt) is absorbed by the exchange's **insurance fund** rather than passed to other traders. The insurance fund is a shared backstop that grows over time and cushions the system against gaps in extreme moves.

The insurance-fund balance is public:

```bash theme={null}
curl "https://<api-host>/perps/insurance-fund"
```

<Tip>
  A healthy insurance fund is a sign of system resilience. In severe conditions where the fund is insufficient, exchanges use additional deleveraging mechanisms as a last resort — so the best protection remains keeping your own positions well-collateralized.
</Tip>

## Practical guidance

* **Preview every order** to see margin required and approval status before sending.
* **Keep headroom** above maintenance margin; don't trade at the edge of your collateral.
* **Use `reduceOnly`** for exit orders and protective stop / take-profit triggers for automated risk exits.
* **Wire `cancel-all`** into your kill path so you can pull all resting orders instantly on a feed loss or risk breach.
