跳到内容

交易

订单生命周期

订单从提交到成交、撤销或到期,经历一组固定状态。每个状态均可通过 API 查询。

本章涉及的接口

四个接口覆盖完整订单生命周期。所有交易接口均需身份验证和相应权限范围。

方法路径用途
POST /orders 提交新订单。
GET /orders/:id 通过 ID 查询单笔订单。
GET /orders 列出您的未成交和近期已完成订单。
POST /orders/:id/cancel 撤销未成交订单。
ACTORClientACTORSatoriEx APIACTORRedis LISTACTORMatcherACTORLedgerACTORWebSocket Hub1POST /orders (validate, escrow funds)2202 Accepted (trades: [])3LPUSH order:pending4BRPOP (pull next order)5match by price-time priority6atomic debit / credit (double-entry)7broadcast trade event over /wsAll seven steps run in the same matcher tick — typical end-to-end latency from POST to WS event is under 500 ms.
The full async flow from a POST /orders call to a trade event delivered over WebSocket. The 202 Accepted (step 2, dashed) lands BEFORE matching runs — your client must await the trade event on /ws to learn the fill outcome.

订单状态

每笔订单持有其中一个状态值。状态转换为单向,部分成交后撤销除外。

ENTRYSubmittedSTATEpendingSTATEopenSTATEpartialSTATEfilledEXITClosedSTATEcancelledPOST /ordersadded to booksome fillsmore fillsfully matchedvalidation failsuser cancelscancel remainder
Transitions are one-way except for the cancel branches: pending, open, and partial can all transition to cancelled by user or admin action. A circuit-breaker halt pauses the market but leaves resting orders intact — cancellation is still your decision. Cancelling a partial order removes only the unfilled remainder.
状态含义
pending在订单簿中挂单,等待对手方订单。
open挂单在订单簿中等待反向委托成交。
partial部分成交,剩余仍在挂单。
filled完全成交。份额已计入您的仓位。
cancelledCancelled 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 订单频道实时推送状态变更。需要响应成交的程序应使用它——轮询适合仪表板但不适合交易循环。