> For the complete documentation index, see [llms.txt](https://docs.flash.trade/flash-trade/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flash.trade/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/previews.md).

# Previews

`POST` endpoints that compute numbers without building a transaction. Each returns `{ "err": "…" }` in the body when the computation fails. Shared conventions: [Conventions](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/conventions.md). Task walkthrough: [Preview fees & PnL](/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/guides/preview-fees-and-pnl.md).

| Method | Path                        |
| ------ | --------------------------- |
| `POST` | `/preview/limit-order-fees` |
| `POST` | `/preview/exit-fee`         |
| `POST` | `/preview/tp-sl`            |
| `POST` | `/preview/margin`           |

***

## Limit-order fees

`POST /preview/limit-order-fees`

Entry price, entry fee, liquidation price, and borrow rate for a would-be position.

| Field            | Type   | Req | Description                                  |
| ---------------- | ------ | --- | -------------------------------------------- |
| `marketSymbol`   | string | ✓   | Market token symbol                          |
| `inputAmountUi`  | string | ✓   | Collateral amount (UI)                       |
| `outputAmountUi` | string | ✓   | Size in target token (UI)                    |
| `side`           | enum   | ✓   | `LONG` / `SHORT`                             |
| `limitPrice`     | string | —   | Limit price (UI); uses live price if omitted |

**Response:** `{ entryPriceUi, entryFeeUsdUi, liquidationPriceUi, borrowRateUi }`.

***

## Exit fee

`POST /preview/exit-fee`

Exit fee and exit price for closing (part of) a position.

| Field              | Type   | Req | Description         |
| ------------------ | ------ | --- | ------------------- |
| `marketSymbol`     | string | ✓   | Market token symbol |
| `side`             | enum   | ✓   | `LONG` / `SHORT`    |
| `closeAmountUsdUi` | string | ✓   | USD to close (UI)   |
| `owner`            | string | ✓   | Owner wallet pubkey |

**Response:** `{ exitFeeUsdUi, exitFeeAmountUi, exitPriceUi }`.

***

## TP/SL

`POST /preview/tp-sl`

`mode` selects the computation: `forward` (trigger price → PnL), `reverse_pnl` (target PnL → trigger price), `reverse_roi` (target ROI% → trigger price).

Supply `owner` to use the caller's existing position; omit it and pass the inline fields to preview before a position exists.

| Field              | Type   | Req | Description                               |
| ------------------ | ------ | --- | ----------------------------------------- |
| `mode`             | string | ✓   | `forward` / `reverse_pnl` / `reverse_roi` |
| `marketSymbol`     | string | ✓   | Market token symbol                       |
| `side`             | enum   | ✓   | `LONG` / `SHORT`                          |
| `owner`            | string | —   | Owner pubkey (owner-position mode)        |
| `entryPriceUi`     | string | —   | Entry price (inline mode)                 |
| `sizeUsdUi`        | string | —   | Position size, USD (inline mode)          |
| `collateralUsdUi`  | string | —   | Collateral, USD (inline mode)             |
| `triggerPriceUi`   | string | —   | Forward: trigger price to price PnL for   |
| `targetPnlUsdUi`   | string | —   | Reverse-PnL: target PnL, USD              |
| `targetRoiPercent` | number | —   | Reverse-ROI: target ROI %                 |

**Response:** `{ pnlUsdUi?, pnlPercentage?, triggerPriceUi?, maxProfitPriceUi? }` — forward returns `pnlUsdUi`/`pnlPercentage`; reverse modes return `triggerPriceUi`.

***

## Margin

`POST /preview/margin`

Preview a collateral add/remove on an existing position.

| Field              | Type   | Req | Description            |
| ------------------ | ------ | --- | ---------------------- |
| `marketSymbol`     | string | ✓   | Market token symbol    |
| `side`             | enum   | ✓   | `LONG` / `SHORT`       |
| `marginDeltaUsdUi` | string | ✓   | Margin delta, USD (UI) |
| `action`           | enum   | ✓   | `ADD` / `REMOVE`       |
| `owner`            | string | ✓   | Owner wallet pubkey    |

**Response:** `{ newLeverageUi, newLiquidationPriceUi, maxAmountUsdUi, existingCollateralUsdUi?, newCollateralUsdUi?, existingLeverageUi?, existingLiquidationPriceUi?, deltaUsdUi? }`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.flash.trade/flash-trade/flash-trade-protocol/build-on-flash/flash-trade-v2/reference/previews.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
