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

# previewCloseTrade

> What closing all or part of an Ostium position would return: exit price, rollover settled, net PnL, and proceeds.

`previewCloseTrade(params)` is the exit mirror of [`previewOpenTrade`](/developer/reference/preview-open-trade). It reports what a full or partial close would return at the live price, including the rollover the close settles.

```ts theme={null}
// Full close
const p = await client.previewCloseTrade({ pairId: 0, idx: 0 });

// Half the position
const half = await client.previewCloseTrade({ pairId: 0, idx: 0, closePercent: 50 });

console.log(half.exitPx);      // after spread — closing takes the other side of the book
console.log(half.rollover);    // settled in proportion to the share being closed
console.log(half.received);    // collateral released + net PnL
```

`pairId` and `idx` come from [`getOpenPositions()`](/developer/reference/get-open-positions).

## Parameters

| Parameter      | Type               | Default          | Description                                                                                        |
| -------------- | ------------------ | ---------------- | -------------------------------------------------------------------------------------------------- |
| `pairId`       | `string \| number` | —                | Pair the position is on.                                                                           |
| `idx`          | `number`           | —                | Position index within the pair — `Position.idx`.                                                   |
| `closePercent` | `number`           | `100`            | Percentage to close, 1–100. The chain carries this at two decimals, so anything finer is rejected. |
| `user`         | `Address`          | connected wallet | Trader who owns the position.                                                                      |
| `blockNumber`  | `bigint`           | current block    | Block used for rollover accrual. Fetched automatically on `OstiumClient`.                          |

## Response schema

```ts theme={null}
interface PreviewCloseTradeResult {
  pairId: string;
  pairFrom: string;
  pairTo: string;
  idx: number;
  isLong: boolean;
  closePercent: string;
  midPx: string;
  exitPx: string;             // expected execution price, after dynamic spread
  priceImpactP: string;       // differs from the open-side figure: closing takes the other side
  sizeClosing: string;        // in base-asset units
  collateralClosing: string;  // collateral being released, in USDC
  leverage: string;
  grossPnl: string;           // PnL at the exit price, before rollover
  spreadCost: string;         // PnL at exit minus PnL at mid — usually negative
  rollover: string;           // settled by this close; positive means the trader pays
  funding: string;            // always "0" — funding is excluded throughout the SDK
  oracleFee: string;          // flat deposit the wallet must hold; refunded on execution
  netPnl: string;             // grossPnl after rollover
  netPnlPercent: string;      // as a percentage of the collateral being closed
  received: string;           // collateral released + net PnL
  isFullClose: boolean;
  warnings: Array<{ code: string; message: string }>;
}
```

## Partial closes

Size, collateral, PnL and rollover all scale with `closePercent`: closing 25% releases a quarter of the collateral and settles a quarter of the accrued rollover.

`oracleFee` is a flat deposit the wallet must hold to submit the close. It is refunded on execution, so it is not deducted from `received` — but a ticket should show it, and block submission when the wallet cannot cover it.

## Related

* [closeTrade](/developer/reference/close-trade)
* [getOpenPositions](/developer/reference/get-open-positions)
