> For the complete documentation index, see [llms.txt](https://docs.fluvion.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fluvion.io/api-trading/trading.md).

# Orders, Leverage & Execution

Live writes require explicit authorization and `trading` scope. These payloads describe the API; they are not an instruction to execute a sample trade.

## Preflight

1. Confirm network, account, exact market, BUY/SELL, margin mode, leverage, order type and maximum notional with the user.
2. Read positions and pending orders. An opposite-side order may reduce an existing position, not create an independent position.
3. Fetch `/v1/public/info/{symbol}` for status, `base_min`, `base_max`, `base_tick`, `quote_tick`, `min_notional` and price constraints. Never hardcode minimums.
4. Fetch current prices/orderbook and free collateral. Validate size/price with decimal-safe arithmetic, not floating-point remainder checks.
5. Reserve margin plus fees and a safety buffer. Fee fields such as `futures_taker_fee_rate` are in basis points (5 bps = 0.05%); verify field units before calculations.
6. If minimum size exceeds the approved cap, stop. Never silently increase leverage or notional.

Notional is quantity × execution price. At configured leverage L, approximate initial margin is notional/L, subject to the risk engine. Configured leverage is not the same as effective account leverage. Cross margin shares collateral across positions.

## Set leverage for one market

```
POST /v1/client/leverages
```

```json
{"symbol":"PERP_ETH_USDC","leverage":3,"margin_mode":"CROSS"}
```

Omitting `symbol` can update all markets: do not omit it for a single-market request. Confirm success, then read back the setting. A successful response may not contain a `data` object. If the order later fails, report any leverage change already made; do not silently assume rollback.

## Submit an order

```
POST /v1/order
```

Illustrative payload only; values must be replaced after live validation:

```json
{
  "symbol":"PERP_ETH_USDC",
  "side":"BUY",
  "order_type":"IOC",
  "order_price":2500,
  "order_quantity":0.0041,
  "client_order_id":"fluvion-unique-attempt-id",
  "margin_mode":"CROSS",
  "reduce_only":false
}
```

IOC executes available quantity within its price limit and cancels the remainder. It can partially fill or not fill. For a buy, limit price × quantity provides a cap on execution notional, excluding fees. For a sell, the limit price is a floor, not a maximum execution-notional cap; an agent must not reuse the buy-side cap calculation for shorts. Enforce an explicitly authorized quantity/exposure policy and supported execution bounds, or stop if the requested hard cap cannot be guaranteed. MARKET orders do not provide the same explicit price ceiling. POST\_ONLY is not a guarantee of no eventual execution.

Generate a unique client order ID (respect the current 36-character limit). Persist the non-secret attempt record before sending. Never automatically submit a second order after a timeout: first reconcile by client order ID using the current endpoint reference. Duplicate prevention must survive process restarts; client IDs may be reusable after an order completes.

## Verify the result

`success: true` on submission means accepted, not filled. Read `GET /v1/order/{order_id}` and reconcile status, executed quantity, average execution price and fees. Then read positions. Distinguish NEW, partial fill, FILLED, cancellation and rejection. Report unknown status as unknown and stop further writes until resolved.

## Cancel and close

Cancel a specific open order via `DELETE /v1/order?order_id=...&symbol=...`, signing the entire query string. Cancellation cannot undo fills and can race with execution. Never use cancel-all as a connectivity test.

Closing a position requires a new opposite-side order with `reduce_only: true`, capped at the current absolute position size and separately authorized. Do not assume revoking a key closes exposure. TP/SL use dedicated algo-order semantics; do not treat an arbitrary trigger field on a normal order as a working protective stop. Validate those flows on testnet before offering automation.


---

# 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.fluvion.io/api-trading/trading.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.
