> ## Documentation Index
> Fetch the complete documentation index at: https://dexbuilder.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 提交訂單

> 透過 Event Contracts API 建立事件合約私有訂單。

在確認 Market 目前接受訂單後，可以針對指定 Outcome Token 提交交易。公開市場資料無需認證；下單屬於私有操作，需要完成認證。

生產環境 Base URL：

```text theme={null}
https://api.dexbuilder.com
```

## 1. 讀取 Market 交易限制

先查詢 Market，並從 `outcomes[].token_id` 中選擇要交易的 Token：

```bash cURL theme={null}
curl "https://api.dexbuilder.com/api/v4/event_contracts/markets/<market_id>"
```

再讀取公開訂單簿：

```bash cURL theme={null}
curl "https://api.dexbuilder.com/api/v4/event_contracts/tokens/<token_id>/order_book?depth=20"
```

提交訂單前應根據響應中的 `min_order_size` 和 `tick_size` 做數量和價格校驗。

## 2. 提交訂單

```bash cURL theme={null}
curl -X POST "https://api.dexbuilder.com/api/v4/broker/event_contracts/orders" \
  -H "Content-Type: application/json" \
  -H "KEY: ${BROKER_API_KEY}" \
  -H "SIGN: ${SIGN}" \
  -H "Timestamp: ${TIMESTAMP}" \
  -H "X-User-Wallet-Address: ${USER_WALLET}" \
  --data '{
    "token_id": "<token_id>",
    "side": "BUY",
    "price": "0.52",
    "size": "10",
    "total_cost": "5.20",
    "order_type": "GTC",
    "order_mode": "LIMIT",
    "client_order_id": "client-order-001",
    "post_only": false,
    "sell_all": false,
    "expire_time": 0
  }'
```

> [!NOTE]
>
> 請使用 Broker API Key，並在 `X-User-Wallet-Address` 中指定屬於當前 Broker 的使用者錢包地址。`SIGN` 須依實際請求方法、路徑、查詢參數和請求主體計算。詳見 [Broker API Key 與簽名](https://dexbuilder.mintlify.site/zh-TW/api-reference/common/broker-authentication.md) 及 [代表使用者存取](https://dexbuilder.mintlify.site/zh-TW/api-reference/common/sub-user-wallet.md)。

## 請求欄位

| 欄位 | 說明 |
| - | - |
| `token_id` | 要交易的 Outcome Token |
| `side` | 訂單方向，例如 `BUY` / `SELL` |
| `price` | 限價，decimal string |
| `size` | 下單數量，decimal string |
| `total_cost` | 某些訂單模式下使用的訂單總成本 |
| `order_type` | 訂單有效方式：`GTC`、`GTD`、`FOK` 或 `FAK` |
| `order_mode` | 下單模式：`LIMIT` 或 `MARKET` |
| `client_order_id` | 可選的客戶端冪等 / 跟蹤 ID |
| `post_only` | 是否只作為 Maker 提供流動性 |
| `sell_all` | 賣出時是否使用全部可用持倉 |
| `expire_time` | 適用時的過期時間，Unix 秒 |

## 接受響應

```json theme={null}
{
  "order_id": "order-123",
  "client_order_id": "client-order-001",
  "status": "processing",
  "created_at": 1782753357
}
```

`processing` 表示訂單請求已受理並開始處理，不代表訂單已成交。後續應透過訂單查詢介面讀取目前的 REST 狀態。

## 下單前檢查

* Market 必須滿足 `accepting_orders: true`；
* `token_id` 應來自 Market 的 `outcomes` 數組；
* `size` 必須滿足 `min_order_size`；
* `price` 必須符合 `tick_size`；
* 價格、數量、金額建議始終使用字串，避免浮點精度誤差；
* 私有請求必須使用正式認證方案。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.