> For the complete documentation index, see [llms.txt](https://docs.nexus.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexus.xyz/api-reference/zh-cn/guides/order-types.md).

# 订单类型

八种订单类型、四种有效期策略，以及每种类型需要哪些字段。

`OrderRequest` 是所有下单操作的请求体：`POST /orders`、`POST /orders/batch`（作为数组元素）和 `POST /orders/preview`，以及它们对应的 `/api/v1` 版本。

**本页介绍跨操作通用、而生成的端点页面没有涵盖的内容**。那些页面说明的是契约为单个操作声明了什么。下面的要求矩阵是构造一个有效订单所必需的，并且在所有这些操作中完全相同。

面向交易者、说明每种类型*用途*的内容，请参见交易所部分的 [订单类型](https://docs.nexus.xyz/exchange/trading/perpetuals/order-types)。

## 下单结构

它支持普通的 `Limit` 和 `Market` 订单，以及六种条件单类型（`StopLimit`、`StopMarket`、`TakeProfitLimit`、`TakeProfitMarket`、`TrailingStop`、`TrailingLimit`）。字段要求取决于 `order_type`：

* **限价类**（`Limit`、`StopLimit`、`TakeProfitLimit`）需要限价 `price`。
* **可触发、非跟踪类**订单（`StopLimit`、`StopMarket`、`TakeProfitLimit`、`TakeProfitMarket`）需要 `trigger_price`（当 `trigger_price` 缺失时，旧的 `stop_price` 字段可作为备用）。
* **`TrailingStop`** 仅支持市价，因此它以市价单形式触发，并需要 `trailing_offset_bps`。它不接受限价 `price` 或 `trigger_price`（触发锚点由标记价格和偏移量推导得出）。
* **`TrailingLimit`** 的跟踪方式与 `TrailingStop` 相同，但触发的是限价单而不是市价单。它同时需要 `trailing_offset_bps`（跟踪触发条件）和 `limit_offset_bps`（触发时的限价偏移量）。它不接受 `price`、`trigger_price` 或 `stop_price`。交易所在触发时根据越过偏移量的那个标记价格计算限价。

### 各订单类型的必填字段

**每种**订单类型都必须提供 `market_id`、`side`、`order_type`、`quantity` 和 `time_in_force`。四个条件字段的处理方式如下：

| `order_type`       | `price` | `trigger_price` | `trailing_offset_bps` | `limit_offset_bps` | 触发后成为   |
| ------------------ | ------- | --------------- | --------------------- | ------------------ | ------- |
| `Limit`            | **必填**  | 不使用             | 忽略                    | 忽略                 | —（立即挂单） |
| `Market`           | 省略      | 不使用             | 忽略                    | 忽略                 | —（立即执行） |
| `StopLimit`        | **必填**  | **必填**          | 忽略                    | 忽略                 | 限价单     |
| `StopMarket`       | 省略      | **必填**          | 忽略                    | 忽略                 | 市价单     |
| `TakeProfitLimit`  | **必填**  | **必填**          | 忽略                    | 忽略                 | 限价单     |
| `TakeProfitMarket` | 省略      | **必填**          | 忽略                    | 忽略                 | 市价单     |
| `TrailingStop`     | 不接受     | 不接受             | **必填**                | 忽略                 | 市价单     |
| `TrailingLimit`    | 不接受     | 不接受             | **必填**                | **必填**             | 限价单     |

矩阵的读法：

* **必填**。缺少该字段时请求会被拒绝。
* **省略**。该字段不属于市价类订单，也没有需要设置的限价。
* **不使用** / **不接受**。契约说明该订单类型不使用这个字段。跟踪类订单改为根据标记价格和偏移量推导其触发条件。
* **忽略**。该字段可以出现，但对该订单类型不起作用。

四种可触发、非跟踪类订单只在触发方向上有所不同。`StopLimit` 和 `StopMarket` 在标记价格朝**不利**方向越过 `trigger_price` 时触发，`TakeProfitLimit` 和 `TakeProfitMarket` 则在朝**有利**方向时触发。

### `stop_price` 已弃用

`stop_price` **已弃用，请改用 `trigger_price`**。规则如下：

* `trigger_price` 是规范的触发阈值。
* `stop_price` **仅作为备用**，在 `trigger_price` 缺失时才被接受。
* 当**两者**都提供时，**以 `trigger_price` 为准**，`stop_price` 被忽略。
* 对于 `Limit`、`Market`、`TrailingStop` 和 `TrailingLimit` 订单，两者都会被完全忽略。

新的集成应发送 `trigger_price`，永远不要发送 `stop_price`。

### 有效期

每个订单都必须提供 `time_in_force`，取值为以下四种策略之一：

| 值          | 含义                                                |
| ---------- | ------------------------------------------------- |
| `GTC`      | 一直有效直至取消（Good-till-cancelled）。挂在订单簿上，直到成交或撤单。     |
| `IOC`      | 立即成交并取消剩余（Immediate-or-cancel）。立即成交能成交的部分，剩余部分撤单。 |
| `FOK`      | 全部成交或立即取消（Fill-or-kill）。要么立即全部成交，要么整笔撤单。          |
| `PostOnly` | 如果订单在进入时会吃掉流动性（穿过订单簿），则拒绝该订单，从而保证它以 Maker 身份挂单。   |

`PostOnly` 是契约中唯一详细描述的取值。上面对 `GTC`、`IOC` 和 `FOK` 的描述给出的是各缩写的标准含义，契约本身并没有写明。

### `OrderRequest` 字段

| 字段                    | 类型                                                                                                                          | 必填        | 描述                                                                                                                                                                                                                                                                                     |
| --------------------- | --------------------------------------------------------------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `market_id`           | string                                                                                                                      | 是         | 市场标识符，例如 `BTC-USDX-PERP`。                                                                                                                                                                                                                                                              |
| `side`                | `Buy` / `Sell`                                                                                                              | 是         | 订单方向。                                                                                                                                                                                                                                                                                  |
| `order_type`          | `Limit` / `Market` / `StopLimit` / `StopMarket` / `TakeProfitLimit` / `TakeProfitMarket` / `TrailingStop` / `TrailingLimit` | 是         | 订单类型。`Limit` 和 `Market` 是无条件订单，其余六种是条件单。`StopLimit` / `StopMarket` 在标记价格朝不利方向越过 `trigger_price` 时触发。`TakeProfitLimit` / `TakeProfitMarket` 在朝有利方向时触发。`TrailingStop` 在标记价格从其观测到的最优极值回撤 `trailing_offset_bps` 时以市价单形式触发。`TrailingLimit` 以同样的方式触发，但挂出一个价格相对触发价偏移 `limit_offset_bps` 的限价单。 |
| `price`               | decimal string                                                                                                              | 视情况       | 限价。限价类订单（`Limit`、`StopLimit`、`TakeProfitLimit`）必填。市价类和跟踪类订单请省略。                                                                                                                                                                                                                        |
| `quantity`            | decimal string                                                                                                              | 是         | 订单数量。以字符串序列化的任意精度十进制数（无损）。请使用十进制类型解析，切勿使用浮点数。                                                                                                                                                                                                                                          |
| `time_in_force`       | `GTC` / `IOC` / `FOK` / `PostOnly`                                                                                          | 是         | 有效期策略。如果订单在进入时会吃掉流动性（穿过订单簿），`PostOnly` 会拒绝该订单，从而保证它以 Maker 身份挂单。                                                                                                                                                                                                                       |
| `reduce_only`         | boolean                                                                                                                     | 否         | 契约声明了该字段，但没有任何描述。参见[已知缺口](/api-reference/zh-cn/guides/known-gaps.md#trading)。                                                                                                                                                                                                          |
| `stop_price`          | decimal string or null                                                                                                      | 否，**已弃用** | **已弃用**。请改用 `trigger_price`。止损 / 止盈类订单的旧触发阈值。仅在 `trigger_price` 缺失时作为备用被接受。两者都提供时，以 `trigger_price` 为准。对于 `Limit`、`Market`、`TrailingStop` 和 `TrailingLimit` 订单会被忽略。                                                                                                                    |
| `trigger_price`       | decimal string or null                                                                                                      | 视情况       | 可触发、非跟踪类订单（`StopLimit`、`StopMarket`、`TakeProfitLimit`、`TakeProfitMarket`）的规范触发阈值，这些订单必须提供它（省略时，旧的 `stop_price` 字段可作为备用）。`Limit`、`Market`、`TrailingStop` 和 `TrailingLimit` 订单不使用该字段。                                                                                                    |
| `trailing_offset_bps` | integer (minimum 0) or null                                                                                                 | 视情况       | 以基点表示的跟踪偏移量（1 bp = 0.01%）。`TrailingStop` 和 `TrailingLimit` 订单必填，其他所有订单类型会忽略。一旦标记价格从其观测到的最优极值回撤该基点数，跟踪触发条件即被触发。`TrailingStop` 触发市价单，`TrailingLimit` 触发一个按 `limit_offset_bps` 定价的限价单。值为 `0` 也被接受，此时会在下单后的第一次标记价格评估时触发（无需回撤）。                                                             |
| `limit_offset_bps`    | integer (0–9999) or null                                                                                                    | 视情况       | 触发后限价的偏移量，以基点表示（仅限 `TrailingLimit`；须与 `trailing_offset_bps` 一同提供）。当跟踪触发条件在 `fire_price` 触发时，注入的限价单挂在 `fire_price` × (1 + offset)（买入）/ × (1 − offset)（卖出），并按最小价格变动向更紧的一侧取整。值为 `0` 时，限价单正好挂在 `fire_price`。其他订单类型会忽略该字段。                                                                  |

### 订单准入由保证金不等式决定

只有在计入订单自身的保证金占用后，账户仍然满足初始保证金要求，交易所才会接受该订单。这就是交易所保证金模型中的订单准入不等式 **(M.13)**。参见[保证金计算](https://docs.nexus.xyz/math-engine/margin-math)。

`POST /orders` 返回原因为保证金不足的 `400`，就是该不等式不成立。使用 `POST /orders/preview` 可以在不提交订单的情况下对其进行评估。


---

# 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.nexus.xyz/api-reference/zh-cn/guides/order-types.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.
