# 委託下單

`POST` `/v1/trade/order`

該接口用於港美股，窩輪，期權的委託下單。

## Parameters

### Request Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `symbol` | string | Yes | 股票代碼，使用 `ticker.region` 格式，例如：`AAPL.US` |
| `order_type` | string | Yes | 訂單類型。可選值：`LO`、`ELO`、`MO`、`AO`、`ALO`、`ODD`、`LIT`、`MIT`、`TSLPAMT`、`TSLPPCT`、`SLO`。 |
| `submitted_price` | string | No | 下單價格，例如：`388.5`. `LO` / `ELO` / `ALO` / `ODD` / `LIT` 訂單必填 |
| `submitted_quantity` | string | Yes | 下單數量，例如：`100`。美股支持碎股數量，例如 `0.05`。美股碎股訂單必須將 `outside_rth` 設為 `RTH_ONLY`，否則會被拒單，返回錯誤碼 `603200`。 |
| `trigger_price` | string | No | 觸發價格，例如：`388.5`. `LIT` / `MIT` 訂單必填 |
| `limit_offset` | string | No | 指定價差。`TSLPAMT` / `TSLPPCT` 訂單在 `limit_depth_level` 為 0 時必填 |
| `trailing_amount` | string | No | 跟蹤金額。`TSLPAMT` 訂單必填 |
| `trailing_percent` | string | No | 跟蹤漲跌幅。`TSLPPCT` 訂單必填 |
| `expire_date` | string | No | 長期單過期時間，格式為 `YYYY-MM-DD`, 例如：`2022-12-05`. time_in_force 為 `GTD` 時必填 |
| `side` | string | Yes | 買賣方向。**可選值：**, `Buy` - 買入，`Sell` - 賣出 |
| `outside_rth` | string | No | 是否允許盤前盤後，美股必填。**可選值：**, `RTH_ONLY` - 不允許盤前盤後，`ANY_TIME` - 允許盤前盤後，`OVERNIGHT` - 夜盤，`OPTION_PRE_MARKET` - 夜盤期權 |
| `time_in_force` | string | Yes | 訂單有效期類型。**可選值：**, `Day` - 當日有效，`GTC` - 撤單前有效，`GTD` - 到期前有效 |
| `remark` | string | No | 備註 (最大 64 字符) |
| `limit_depth_level` | integer | No | 指定買賣檔位，取值範圍為 -5 ～ 0 ～ 5，負數代表買盤檔位（例如 -1 表示買一），, 正數代表賣盤檔位（例如 1 表示賣一），當為 0 時 limit_offset 參數生效，`TSLPAMT` / `TSLPPCT` 訂單有效 |
| `monitor_price` | string | No | 監控價格，需要達到該價格才會開始監控，更新參考價，`TSLPAMT` / `TSLPPCT` 訂單有效 |
| `trigger_count` | integer | No | 觸發次數，取值範圍 0 ~ 3，表示在 1 分鐘內觸發多次才會觸發訂單，, `LIT` / `MIT` / `TSLPAMT` / `TSLPPCT` 訂單有效 |
| `client_request_id` | string | No | 冪等性請求 ID，用於防止重複下單。服務器會快取該請求 ID 10 分鐘。在此期間內如果收到相同 ID 的請求，將返回原始響應而不建立重複訂單。必須是唯一標識符（如 UUID）。 |
| `attached_params` | object | No | 附加單參數（止盈止損） |
| `attached_params.attached_order_type` | string | No | 附加單訂單類型。**可選值：**, `PROFIT_TAKER` - 止盈，`STOP_LOSS` - 止損，`BRACKET` - 括號單 |
| `attached_params.profit_taker_price` | string | No | 止盈觸發價格 |
| `attached_params.stop_loss_price` | string | No | 止損觸發價格 |
| `attached_params.time_in_force` | string | No | 附加單有效期類型。**可選值：**, `Day` - 當日有效，`GTC` - 撤單前有效，`GTD` - 到期前有效（此時繼承主單 expire_date） |
| `attached_params.expire_time` | integer | No | 到期時間（Unix 時間戳，單位秒） |
| `attached_params.activate_order_type` | string | No | 觸發後提交的訂單類型，例如 `LIT`（限價單）或 `MIT`（市價單） |
| `attached_params.profit_taker_submit_price` | string | No | 止盈限價委託價格，`activate_order_type` 為 `LIT` 時必填 |
| `attached_params.stop_loss_submit_price` | string | No | 止損限價委託價格，`activate_order_type` 為 `LIT` 時必填 |
| `attached_params.activate_rth` | string | No | 觸發後提交的訂單是否允許盤前盤後。**可選值：**, `RTH_ONLY` - 不允許盤前盤後，`ANY_TIME` - 允許盤前盤後 |
| `attached_params.profit_taker_depth_level` | integer | No | 止盈限價委託價格的買賣檔位，`activate_order_type` 為 `LIT` 時有效 |
| `attached_params.stop_loss_depth_level` | integer | No | 止損限價委託價格的買賣檔位，`activate_order_type` 為 `LIT` 時有效 |

## Request Example

```bash
curl --request POST \
  --url 'https://openapi.longbridge.com/v1/trade/order' \
  --header 'Authorization: Bearer <access_token>' \
  --header 'Content-Type: application/json' \
  --data '{"symbol":"<symbol>","order_type":"<order_type>","submitted_price":"<submitted_price>","submitted_quantity":"<submitted_quantity>","trigger_price":"<trigger_price>","limit_offset":"<limit_offset>","trailing_amount":"<trailing_amount>","trailing_percent":"<trailing_percent>","expire_date":"<expire_date>","side":"<side>","outside_rth":"<outside_rth>","time_in_force":"<time_in_force>","remark":"<remark>","limit_depth_level":0,"monitor_price":"<monitor_price>","trigger_count":0,"client_request_id":"<client_request_id>","attached_params":{"attached_order_type":"<attached_order_type>","profit_taker_price":"<profit_taker_price>","stop_loss_price":"<stop_loss_price>","time_in_force":"<time_in_force>","expire_time":0,"activate_order_type":"<activate_order_type>","profit_taker_submit_price":"<profit_taker_submit_price>","stop_loss_submit_price":"<stop_loss_submit_price>","activate_rth":"<activate_rth>"}}'
```

## Response

### Response JSON Example

```json
{
  "code": 0,
  "message": "success",
  "data": {
    "order_id": 683615454870679600
  }
}
```
