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

# getMaxCollateral

> The largest collateral an Ostium trade can use, and which limit is stopping it going higher.

`getMaxCollateral(params)` returns what a **Max** button should fill in, and which limit stopped it there — so a UI can explain why, rather than showing a number that refuses to grow.

```ts theme={null}
const { max, bound, limits } = await client.getMaxCollateral({
  pairId: 0,
  isLong: true,
  leverage: 10,
});

console.log(max);     // "13204.51" — fill this into the collateral field
console.log(bound);   // "openInterest" — why it stopped here
console.log(limits);  // every ceiling considered
```

The connected trader's wallet balance and USDC allowance are included automatically. Call it on `OstiumSubgraphClient` for the protocol-side limits only.

## Parameters

| Parameter  | Type               | Default          | Description                                                         |
| ---------- | ------------------ | ---------------- | ------------------------------------------------------------------- |
| `pairId`   | `string \| number` | —                | Pair the trade would open on.                                       |
| `isLong`   | `boolean`          | —                | Direction — each side has its own open-interest headroom.           |
| `leverage` | `number`           | —                | Leverage the trade would use. Open-interest headroom depends on it. |
| `user`     | `Address`          | connected wallet | Trader whose balance and allowance to fold in.                      |

## Response schema

```ts theme={null}
interface MaxCollateralResult {
  max: string;    // the binding value — what a Max button fills in
  bound: 'openInterest' | 'groupCollateral' | 'perTradeMax' | 'balance' | 'allowance' | 'none';
  limits: {
    openInterest: string;     // headroom under this side's OI cap, at this leverage
    groupCollateral: string;  // headroom under the group's share of vault liquidity
    perTradeMax: string;      // MAX_COLLATERAL_USD
    balance?: string;         // trader's USDC balance — only when a trader was resolved
    allowance?: string;       // USDC allowance to TradingStorage — same
  };
}
```

`groupCollateral` can come back as `"unknown"` when the vault balance could not be read. `max` then reflects only the limits that were checked.

<Warning>
  `max` is point-in-time. The open-interest cap is denominated in USD, so it moves with the price — a value sitting exactly on the boundary can be rejected moments later. Re-run [`previewOpenTrade()`](/developer/reference/preview-open-trade) before enabling submit, or apply your own margin.
</Warning>

## Related

* [previewOpenTrade](/developer/reference/preview-open-trade)
* [getBalances](/developer/reference/get-balances)
