Sub topic 12
Order States from Submission to Completion
What happens after you submit an order
Assume you already understand trading pairs, basic order books, and simple Python. This chapter focuses on the lifecycle of an order after you click Buy or Sell. An order lifecycle is the sequence of states an order passes through from submission to its final result.
An exchange usually assigns each order a unique ID. You can use this ID to track updates through the exchange website, API, or WebSocket stream. The exact state names differ between exchanges, but the process is similar.
| State | Meaning | Can it trade? |
|---|---|---|
| Pending or accepted | The exchange received and is checking the order | Usually not yet |
| New or open | The order passed checks and is on the book | Yes |
| Partially filled | Some quantity traded, but some remains | Yes |
| Filled | The entire requested quantity traded | No |
| Canceled | The remaining quantity was removed | No |
| Rejected | The exchange refused the order | No |
| Expired | The order ended because its time limit passed | No |
The normal lifecycle
When your client sends an order, it first travels to the exchange. The exchange checks the symbol, quantity, price, account permissions, and available balance. A market order may also be checked against available liquidity.
If the checks pass, the exchange acknowledges the order. A limit order that does not immediately match becomes open or new on the order book. A limit order that crosses the spread may trade immediately instead.
Each trade produces an execution, sometimes called a fill. The execution includes a quantity, price, fee, and timestamp. If the order requests 5 units and only 2 units trade, the order becomes partially filled. The remaining 3 units stay active unless the order's rules remove them.
A filled order has no remaining quantity. A canceled order can have either zero fills or a partial fill before cancellation. Therefore, “canceled” does not always mean “nothing happened.”
Final states and cancellation races
Filled, canceled, rejected, and expired are terminal states. An order should not move out of one of these states. However, a cancellation request can race with a matching event.
For example, you submit a cancel request while the matching engine is processing a trade. The trade may happen first. The exchange can then report a partial fill followed by cancellation. Your software should read the actual execution quantity rather than assuming the cancel succeeded before any trade.
A cancel request can also fail because the order was already filled, already canceled, or unknown to the exchange. Treat the exchange's response as the source of truth.
Tracking an order safely
For automated trading, store the order ID, requested quantity, cumulative filled quantity, average fill price, fee, and final status. Process updates in a way that tolerates duplicates and messages arriving out of order. Many exchanges provide both a live user-data stream and a REST endpoint for recovery.
A simple reconciliation rule is:
remaining = requested_quantity - cumulative_filled_quantity- If
remainingis zero, the order is filled even if a later status message is delayed. - If the final status is canceled or expired, record the filled quantity before closing the order.
When a connection breaks, reconnect and request the order's current state. Do not submit a replacement order until you know whether the original order traded. Otherwise, both orders might fill.
Exercise
An order requests 10 BTC, fills 6 BTC, and is then canceled. How much BTC should your records show as traded and as remaining?
Show answer
Record 6 BTC as traded and 4 BTC as canceled remaining quantity. The final state is canceled, but the order was partially filled.