交易
订单生命周期
订单从提交到成交、撤销或到期,经历一组固定状态。每个状态均可通过 API 查询。
本章涉及的接口
四个接口覆盖完整订单生命周期。所有交易接口均需身份验证和相应权限范围。
| 方法 | 路径 | 用途 |
|---|---|---|
| POST | /orders | 提交新订单。 |
| GET | /orders/:id | 通过 ID 查询单笔订单。 |
| GET | /orders | 列出您的未成交和近期已完成订单。 |
| POST | /orders/:id/cancel | 撤销未成交订单。 |
订单状态
每笔订单持有其中一个状态值。状态转换为单向,部分成交后撤销除外。
| 状态 | 含义 |
|---|---|
| pending | 在订单簿中挂单,等待对手方订单。 |
| open | 挂单在订单簿中等待反向委托成交。 |
| partial | 部分成交,剩余仍在挂单。 |
| filled | 完全成交。份额已计入您的仓位。 |
| cancelled | Cancelled by the user or by an admin action. The circuit breaker halts the market on a 30%+ price move but does not automatically cancel resting orders — they are paused until trading resumes (or you cancel them yourself). |
常见拒绝原因
订单被拒绝时,响应包含稳定的错误码,供客户端据此分支处理。
| 错误码 | 符号 | 含义 |
|---|---|---|
| 3001 | ErrInsufficientBalance | 您的 USDC 余额不足以按建议价格下单。 |
| 5002 | ErrInvalidPrice | 价格超出市场允许的价格范围,或低于 0 / 高于 1。 |
| 5004 | ErrInvalidSide | side must be 1 (buy) or 2 (sell) — any other value is rejected. |
| 5007 | ErrMarketNotTrading | 市场已暂停(熔断机制、裁决或维护)。 |
| 5008 | ErrInsufficientPosition | you do not hold enough shares of this outcome to place this sell order. |
| 2025 | ErrTwoFactorRequired | 2FA is required for trading — enable it in Security settings before placing orders. |
请基于数值 `code` 字段分支处理,而非基于 message——消息是面向用户的,会随语言环境和平台文案变化。
订阅订单事件,避免轮询
WebSocket 订单频道实时推送状态变更。需要响应成交的程序应使用它——轮询适合仪表板但不适合交易循环。