Concept

Order Lifecycle

Definition

An order's lifecycle is the sequence of states it passes through from the moment it is submitted to a broker until it reaches a terminal state. The canonical states are pending submission (built but not yet sent), accepted (acknowledged by the broker), working (live on the exchange book), partially filled (some quantity has traded, some remains), filled (the full quantity has traded), rejected (the broker or exchange refused the order), and cancelled (the trader or system pulled the order before it filled). Time-in-force flags add expiry states such as day-cancelled and good-till-cancelled.

The lifecycle is a state machine, and every production execution system is built around handling its transitions. Each event — accept, partial fill, fill, reject, cancel acknowledgement — arrives asynchronously from the broker API, and the system must reconcile every event against its internal record of pending and working orders.

Why it matters

How it works

A typical execution layer maintains, for each working order, a record carrying the client order ID, the broker order ID, the requested quantity, the cumulative filled quantity, the average fill price, the current state, and the last update timestamp. Every event from the broker — order acknowledgement, partial fill, full fill, reject, cancel — flows through a handler that updates the appropriate record. Downstream consumers (position keeper, P&L calculator, risk monitor) subscribe to those state changes.

The hardest cases are the ones that look like they should be impossible. An order is sent to cancel while a partial fill is in flight, and both events arrive within milliseconds — the order may end up fully filled even though the trader believed it was cancelled. A broker disconnect leaves several orders in unknown states; the reconnect protocol must query each order to learn what happened. A symbol halts mid-day and pending orders are cancelled by the exchange without the broker proactively notifying. Production-grade systems handle each of these by treating the broker's view as authoritative and reconciling local state against it on every meaningful event.

Where it goes next

Continue exploring

Tags