> ## 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.

# previewOpenTrade

> Everything an Ostium order ticket shows before a trade is signed: execution price, fees, liquidation price, and preflight warnings.

`previewOpenTrade(params)` returns the numbers an order ticket displays before submission — execution price after dynamic spread, the fee breakdown, collateral left backing the position, resulting liquidation price, and the checks that should disable the submit button.

Every value derives from `@ostium/formulae`, the same math the contracts run.

```ts theme={null}
const preview = await client.previewOpenTrade({
  pairId: 0,
  isLong: true,
  collateral: 100,
  leverage: 10,
});

console.log(preview.entryPx);          // price after dynamic spread
console.log(preview.fees.total);       // deducted from collateral at open
console.log(preview.liquidationPx);

if (!preview.isValid) {
  console.warn(preview.warnings.map(w => w.code));
}
```

`builderFeeBps` defaults to the fee configured on the client, so the ticket quotes the fee the trade will actually pay. Pass `0` to preview without one.

<Note>
  The preview takes numbers and `isLong`; `openTrade()` takes decimal strings and `buy`.
</Note>

## Parameters

| Parameter       | Type               | Default       | Description                                                                                                                   |
| --------------- | ------------------ | ------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `pairId`        | `string \| number` | —             | Pair to preview.                                                                                                              |
| `isLong`        | `boolean`          | —             | Direction.                                                                                                                    |
| `collateral`    | `number`           | —             | Gross collateral in USDC, before fees.                                                                                        |
| `leverage`      | `number`           | —             | Leverage the trade would use.                                                                                                 |
| `limitPrice`    | `number`           | live bid/ask  | Trigger price for a limit or stop order. Omit for a market order, which prices off the live book and pays the dynamic spread. |
| `isDayTrade`    | `boolean`          | `false`       | Day trades get the pair's higher intraday leverage cap.                                                                       |
| `builderFeeBps` | `number`           | client config | Builder fee in basis points to include in the quote.                                                                          |

## Response schema

```ts theme={null}
interface PreviewOpenTradeResult {
  pairId: string;
  pairFrom: string;
  pairTo: string;
  isLong: boolean;
  midPx: string;                 // live mid price
  refPx: string;                 // the side's bid/ask, or the limit price
  entryPx: string;               // expected execution price, after spread
  priceImpactP: string;          // dynamic spread applied, as a percentage
  spreadDecaySeconds: number;    // until the current imbalance spread decays to zero
  fees: {
    openFee: string;             // protocol opening fee
    oracleFee: string;           // flat price-retrieval fee
    builderFee: string;          // charged on notional; "0" with no builder
    builderFeeBps: string;
    total: string;               // deducted from collateral at open
    openFeePercent: string;      // blended rate actually applied
    takerFeePercent: string;
    makerFeePercent: string;
    takerNotional: string;
    makerNotional: string;
  };
  collateral: string;            // gross, as supplied
  collateralAtOpen: string;      // what actually backs the position, after fees
  exposure: string;              // collateralAtOpen × leverage
  positionSize: string;          // in base-asset units
  leverage: string;
  liquidationPx: string;
  effectiveMaxLeverage: string;  // accounts for the day-trade cap
  minLeverage: string;
  minPositionSize: string;
  isDayTrade: boolean;
  withinExposureLimit?: boolean; // undefined when the vault balance could not be read
  isValid: boolean;              // true when warnings is empty
  warnings: Array<{ code: string; message: string }>;
}
```

## Warnings

`warnings` covers the preflight conditions a ticket should surface, and `isValid` is simply `warnings.length === 0`.

| Code                      | Meaning                                                          |
| ------------------------- | ---------------------------------------------------------------- |
| `BELOW_MIN_COLLATERAL`    | Collateral is under `MIN_COLLATERAL_USD`.                        |
| `ABOVE_MAX_COLLATERAL`    | Collateral is over `MAX_COLLATERAL_USD`.                         |
| `LEVERAGE_ABOVE_MAX`      | Above the pair's effective max leverage.                         |
| `LEVERAGE_BELOW_MIN`      | Below the group's minimum leverage.                              |
| `BELOW_MIN_POSITION_SIZE` | Notional is under the pair's minimum.                            |
| `FEES_EXCEED_COLLATERAL`  | Fees would consume the whole position.                           |
| `ABOVE_EXPOSURE_LIMIT`    | Breaches the pair's open-interest or the group's collateral cap. |
| `MARKET_CLOSED`           | The market is closed.                                            |
| `DAY_TRADING_CLOSED`      | Intraday trading is closed for this pair.                        |

The list is not exhaustive, and chain state moves between preview and submission — keep normal error handling around `openTrade()`.

## Related

* [getMaxCollateral](/developer/reference/get-max-collateral) — what a Max button should fill in
* [previewCloseTrade](/developer/reference/preview-close-trade) — the exit mirror
* [openTrade](/developer/reference/open-trade)
