A signal is not a trade: following an order to its actual conclusion
Follow an order through submission, acknowledgement, partial fills and cancellation, then reconcile quantities, duplicate events and a restart without inventing certainty.

The screen says cancelled, but the account has changed
The operator sees a cancellation confirmation and relaxes. A moment later, a fill notification appears. It looks as though a cancelled order has traded after its cancellation. That is one possible problem, but not the only explanation. The fill may have occurred while cancellation was still pending, and its report may simply have arrived later. Understanding the difference requires a history of events, not a single coloured status badge.
We will follow a hypothetical order to buy 10,000 EUR against USD. It receives a fill of 4,000 EUR at 1.1000 and another of 3,000 EUR at 1.1002. The remaining 3,000 EUR are cancelled. Assume a generic order contract that permits partial execution and a resting remainder, with a buy limit of 1.1003 and no fees in the arithmetic. The example is not an assertion that a particular OANDA order type exposes this exact sequence, and it is not a record of actual trading.
Its final arithmetic is straightforward: 7,000 EUR filled, USD quote consideration of 7,700.6, and a weighted average price of approximately 1.100085714 USD per EUR. The interesting problem is how the local system reaches those facts when messages are delayed, duplicated or interrupted by a restart. A correct final total does not excuse an unsafe intermediate decision. Resubmitting the order during an uncertain interval could create an entirely different exposure before reconciliation eventually discovers the mistake.
The lifecycle starts before a network request and ends after the last ordinary order status. It includes the intention, the evidence supporting submission, each accepted execution and the final comparison with the broker’s records. A signal expresses a desired action; an execution establishes an actual change. Keeping those concepts separate gives every later message a clear question to answer: what new fact does this message establish, and which uncertainty does it leave unresolved?
Make the intention durable before sending it
In our invented timeline, a signal occurs at 10:00:00.000 UTC. The local process records its intention at an offset of 10 milliseconds and submits a request at 20 milliseconds. Those offsets describe a teaching example, not a latency target or benchmark. Recording the intention before transmission creates a durable account of why the system was about to act, even if it stops immediately after writing to the connection.
The intention identifies the instrument, side, requested quantity, order constraints and the decision that authorized it. It also records the relevant account context and a stable local identifier. A strategy version or input snapshot reference can explain the origin of the decision without embedding every market observation in the order record. Sensitive access credentials do not belong in that history; the event needs to describe the action rather than preserve authentication material.
Local acceptance is not broker acceptance. A risk check may approve the intention while the broker subsequently rejects the request. Conversely, a request may reach the broker even if the local process fails before recording a response. The state after submission therefore describes what is known, not what the application hoped would happen. “Submitted, outcome unknown” is a meaningful state that cannot safely be replaced with “not sent.”
Consider the two crash boundaries. If the process stops after persisting the intention but before any transmission attempt, the recovery path can identify an unsent candidate. If it stops after starting transmission, the persisted record must show that delivery may have occurred. Treating both cases identically creates a retry policy that can duplicate business actions. The distinction is especially important when the networking library retries requests automatically.
The durable record does not make the whole workflow atomic across machines. It narrows the uncertainty and gives recovery something to reconcile. A local transaction can atomically store an intention and queue work, but it cannot unilaterally guarantee that a remote broker accepts exactly one order. That guarantee, when available, depends on the remote contract and the scope of the identifier used to request it.
Separate identity from idempotency
Give the intention a fictional client identifier, intent-A. When the broker accepts it, suppose it assigns broker identifier order-B. The two executions receive identifiers fill-C and fill-D. These names refer to different entities. Repeating the broker order identifier in a log does not identify which fill has been processed, and a new HTTP request identifier does not necessarily mean a new business order.
OANDA’s official order definitions identify an order within its account and describe client extensions. That documented scope matters: an identifier should be stored with the account and provider context that makes it meaningful. The presence of a client identifier field does not, by itself, establish a general retry or idempotency guarantee.
For the hypothetical local ledger, use a composite identity containing provider, account and the relevant remote event identifier. Store the relationship from intent-A to order-B and from order-B to each fill. If one order can be replaced by another remote identifier, preserve that relationship as a chain rather than overwriting the first identifier. Investigation should be able to start from either the original intention or a later fill and find the same business history.
Idempotency has a scope and a lifetime. A server might reject a repeated client identifier, return the original result, or interpret the request according to some other documented rule. Those behaviours are not interchangeable. A key might be unique within an account, session or retention period. Local deduplication of received messages cannot create remote idempotency for a command that has already been sent twice.
An application can nevertheless enforce a useful local invariant: the same accepted fill event must affect its position ledger only once. Store the event and the applied accounting change together, or use a replayable projection with a durable processed-event identity. Checking an in-memory set and then updating a balance leaves a crash boundary between the two operations. The intended guarantee is about one application of one event, not about pretending that every network message will arrive once and in order.
An acknowledgement answers a specific question
In the example, the broker accepts order-B at offset 30 milliseconds and the acceptance reaches the client at 50 milliseconds. A network-level success, an application-level acceptance and an execution report are different observations. An HTTP response code may describe successful request handling while the response body carries the business transactions needed to understand the outcome. Read both according to the endpoint contract.
For a concrete reference, OANDA’s order endpoints document creation responses containing order-related transactions and separate cancellation operations. They demonstrate why an integration must inspect the documented response structure. They do not turn the generic timeline here into a promise about the lifecycle of every order type or account configuration.
Accepted does not mean filled. After receiving acceptance at offset 50, our client knows that the remote order exists under the assumed contract. It does not yet know that any EUR have been bought. A user interface can display the requested quantity and the accepted limit, but should not add 10,000 EUR to the filled quantity or calculate an entry price from the requested limit.
The first fill occurs at offset 80 and reaches the client at 110. Keeping both event time and reception time explains what happened remotely and what the client knew locally. For the teaching timeline, assume the clocks are aligned. In a real integration, clock error and timestamp precision limit any latency calculation; subtracting two printed times is not automatically a reliable network measurement.
At offset 100, the broker has executed 4,000 EUR but the client has not yet received that evidence. A historical reconstruction can describe the execution at its event time. A replay of the client’s decisions must delay its availability until reception. This is the order-management counterpart of distinguishing observation time and availability time in missing market bars. In both settings, information arriving later cannot be inserted into an earlier decision merely because it describes an earlier event.
Let the fill ledger carry the arithmetic
The first execution contributes 4,000 multiplied by 1.1000, or 4,400 USD of quote consideration. The second contributes 3,000 multiplied by 1.1002, or 3,300.6 USD. Together they account for 7,000 EUR and 7,700.6 USD. Dividing quote consideration by filled base quantity gives 1.100085714285714 as the weighted average, displayed here to nine decimal places as 1.100085714.
This is a quantity-weighted calculation. The simple average of the two prices would be 1.1001 because it gives both fills equal weight despite their different sizes. Dividing 7,700.6 by the requested 10,000 would produce 0.77006, which is not the execution price. Only filled quantity belongs in the average-price denominator. The unfilled remainder contributes neither EUR nor quote consideration to these calculations.
FIX’s Trade specification describes ExecutionReport messages and the cumulative fields CumQty, LeavesQty and AvgPx. It gives the active-order quantity relationship and notes exceptions for inactive states. The field names are useful vocabulary; the exact messages, field availability and conventions still belong to the counterparty’s implementation contract.
Before cancellation, after both fills, the active quantities reconcile as 10,000 requested equals 7,000 filled plus 3,000 still available for execution. After cancellation, the leaves quantity in our model is zero. The terminal accounting becomes 10,000 requested equals 7,000 filled plus 3,000 cancelled, with no active remainder. Do not keep reporting 3,000 as executable merely to preserve the active-order equation after the order becomes inactive.
Keep base quantity, quote consideration, fees and realized profit in separate fields. The 7,700.6 USD here is the price-times-quantity amount associated with execution, not profit and not a universal cash-debit rule for every margined product. Our arithmetic excludes fees and conversion. Monetary storage should preserve the contract’s decimal precision; rounding the average for display should not alter the underlying fill amounts or make later reconciliation depend on a rounded screen value.
Cancellation races with execution
At offset 120 milliseconds, after learning about the first fill, the client requests cancellation. It currently knows 4,000 EUR are filled and believes 6,000 remain active. At offset 140, the broker marks cancellation pending. Before it completes cancellation, another 3,000 EUR execute at offset 145. The pending notification reaches the client at 150. Cancellation takes effect at 170, retiring the remaining 3,000 EUR.
The cancellation acknowledgement arrives at offset 190, but the second fill report arrives only at 210. To make the reconciliation problem explicit, assume the acknowledgement includes the final cumulative filled quantity of 7,000. At 190, the client therefore knows the order is cancelled and that its detailed fill ledger, still containing only 4,000 EUR, is incomplete by 3,000 EUR. It should display that discrepancy rather than fabricating a price for the missing execution.
The FIX order-state-change scenarios explicitly include executions during pending cancellation and cancellation requests crossing other messages. They also distinguish pending cancellation from completed cancellation. Our times and quantities are original hypothetical values used to reason about that class of interaction, not measurements from those documents.
A cancellation request is an intention to stop the remainder. It is not a reversal of fills and does not establish the effective cancellation time by itself. At 210, the delayed fill report completes the local detail: fill-D occurred at 145, before cancellation became effective at 170. The report arrived after the acknowledgement, but the economic event did not occur after the cancellation in this example.
Receipt order is not necessarily business-event order. The model must preserve both. If the acknowledgement instead lacked a cumulative quantity, the client would know less at 190 and would need history or reconciliation to establish the final filled total. That variant changes the available evidence, not the rule that an ordinary business cancellation cannot erase executions already completed. A separate trade correction or cancellation would need its own explicit event and accounting treatment.
A status is a projection of a richer history
One status field cannot fully describe the example at offset 190. The order is cancelled, its reported cumulative filled quantity is 7,000, its executable remainder is zero, and the client has detailed records for only 4,000. Calling the whole object “complete” would hide a reconciliation problem. Calling it “partially filled” without mentioning cancellation could imply that more execution is still possible.
Use separate dimensions: local submission knowledge, remote order state, known execution totals, command state and reconciliation status. They can be projected from an immutable event ledger for convenient display. The projection is replaceable; the evidence is not. If a display rule changes, replay the stored events to rebuild the view rather than rewriting history to resemble the new labels.
For the teaching state matrix, an accepted order has zero filled and 10,000 active. After the first fill it has 4,000 filled and 6,000 active. While cancellation is pending after the second fill, it has 7,000 filled and 3,000 active. Once cancellation is effective, it has 7,000 filled, zero active and 3,000 cancelled. These rows describe the remote business state; the client’s knowledge may trail behind them.
A pending-command dimension is particularly valuable. Cancellation can be pending while the quantity changes. Likewise, a replacement request can be unresolved while the original order remains executable. Flattening these dimensions into a small list of mutually exclusive labels forces important information out of the model. A user-facing summary can still be concise if it pairs the primary state with quantities and an uncertainty marker.
Do not implement terminal status as “discard every later event.” A later message may be a duplicate, a delayed earlier fill, a reconciliation response or an explicit correction. Each needs classification. Terminal ordinary order state means that no remaining quantity is active under the established contract. It does not mean the network has delivered every fact about the order, nor that all subsequent accounting events are impossible.
Duplicate messages must not become duplicate fills
Suppose fill-C is received again during a reconnect. Its payload still says 4,000 EUR at 1.1000. Appending another accounting entry because the message arrived twice would raise the recorded filled quantity from 7,000 to 11,000 EUR after fill-D is included. The erroneous quote total would become 12,100.6 USD. Both exceed the legitimate execution history, and the filled quantity would even exceed the original request.
The correct result after an exact replay is still 7,000 EUR and 7,700.6 USD. Deduplicate by event identity, not by matching price and quantity. Two legitimate executions can have identical prices, sizes and even coarse timestamps. A content-only rule could erase one of them. Conversely, a repeated event identifier carrying changed content is a discrepancy to investigate, not an ordinary duplicate to ignore without inspection.
Separate last-fill quantities from cumulative snapshots. If one report says cumulative quantity 4,000 and a later report says cumulative quantity 7,000, adding those two fields produces the same erroneous 11,000. A cumulative value describes a state at a point in the history. It is not an incremental execution quantity. In our ledger, the increments are 4,000 and 3,000, each supported by its own execution identity.
Out-of-order processing requires similar care. An old acceptance arriving after a fill should not reset the filled quantity to zero. A pending-cancellation message arriving after confirmed cancellation should not automatically reactivate the order. Use the protocol’s sequencing and event relationships where available, retain contradictory evidence and request reconciliation when the ordering cannot be established. Timestamp sorting alone may not resolve ties, corrections or clock differences.
Preserving original receipt order remains valuable even if the projection uses a different business ordering. It explains why the client briefly knew an incomplete story. An audit that sorts all events into a neat final timeline and discards reception metadata cannot reproduce that period of uncertainty. It may show correct accounting while concealing the very decision risk that the incident investigation needs to evaluate.
Rejection and timeout leave different kinds of work
A cancellation can be rejected because the order can no longer be cancelled, because the identifier is wrong or for another reason defined by the counterparty. The response must be interpreted with the current order evidence. A rejection of the cancellation request is not automatically a rejection of the original order. The original order may remain active, may already be filled or may require reconciliation before its state is known.
Consider a counterfactual version of our example: the second fill consumes all 6,000 EUR that remained after fill-C. The order is then fully filled at 10,000 EUR, so a later cancellation cannot retire a remainder. A response saying cancellation was too late should preserve those fills. The desired action failed, but the economic action has already happened. Retrying cancellation indefinitely would not change that fact.
Now consider a timeout with no response. Timeout means the local wait ended, not that the broker rejected the command. The request might never have arrived, might still be processing, or might have completed with its response lost. If this was the original creation request, sending a new order under a new identifier could duplicate the intended purchase. If it was a cancellation, assuming success could leave an executable remainder unmanaged.
The recovery path should search for the known client and broker identities using the documented read and history facilities, then compare the resulting evidence with the local intention. Where the contract supports a safe retry under a specific idempotency rule, apply that exact rule. Otherwise retain the unknown state until the ambiguity is resolved or escalated under the system’s operating procedure.
Unknown is a state to manage, not a synonym for failure. The interface should show the affected quantity and unresolved command so that an operator does not create a second action to compensate for a first action that may already exist. A deadline can trigger investigation or suspension of new dependent commands. It cannot manufacture the remote fact needed to declare the order absent or the cancellation effective.
Replacement creates another race, not an editable past
Suppose, instead of cancelling, the client wants to reduce the total order target from 10,000 EUR to 8,000 EUR after seeing the first 4,000 EUR fill. Under a hypothetical replacement contract where the requested quantity denotes the total across the order chain, the desired unfilled amount would initially be 4,000 EUR. But fill-D might occur while the replacement is pending, bringing the executed total to 7,000 EUR before the change takes effect.
If that replacement is accepted with an 8,000 EUR total target, the remaining active amount is now 1,000 EUR. It is not the 4,000 EUR that the client computed before sending the request. Recompute the remainder from confirmed cumulative fills. A replacement request expresses desired new terms; it cannot freeze the world while the request travels.
A second counterexample reduces the desired total to 6,000 EUR, but 7,000 EUR have already executed by the time the request is considered. The new target is below the amount already filled. The response depends on the documented contract, but no ordinary modification can make the completed purchase disappear. The client must not silently reduce its fill ledger to match its desired target.
Quantity semantics are central. Some interfaces express a new total; others may represent a remaining amount or implement replacement through cancellation and creation of another order. Sending 6,000 as a fresh additional order after 7,000 have filled could create 13,000 EUR of total purchases if it all executes. That arithmetic is a diagnostic illustration, not a claim about the behaviour of a named endpoint.
Preserve the relationship between the original request, the replacement command and any new broker identifier. While the change is unresolved, avoid assuming that the original remainder is gone or that both versions are independently executable. The evidence must establish which terms are effective. If an interface implements cancellation followed by creation, test the failure boundary between those actions: cancellation may succeed while creation fails, leaving a different outcome from an atomic modification. The application should report that outcome explicitly rather than presenting an apparently seamless edit.
Order state is not position state
Our completed order is cancelled with 7,000 EUR filled. If the account began flat and no other activity occurred, those fills establish a net purchase of 7,000 EUR under the example’s simplified exposure model. The zero leaves quantity says there is no executable remainder on this order. It says nothing about whether the acquired exposure has subsequently been closed.
For a contrasting hypothetical account, assume an initial net short exposure of 5,000 EUR. The same purchase of 7,000 EUR leaves a net long exposure of 2,000 EUR in a netting model. The order’s own fill ledger is unchanged: it still records 7,000 EUR purchased. The order describes an action; the position aggregates actions. A system that equates a cancelled order with a flat account would misread both examples.
Separate trade identifiers, position identifiers and order identifiers according to the provider’s model. OANDA’s transaction definitions expose order-fill and order-cancel transaction types and fields connecting fills with trade effects. Those definitions provide a concrete example of the distinction; account modes and product conventions still determine how a particular fill changes positions.
An account can also contain activity from another strategy or a manual action. Reconciliation must therefore compare the entire relevant account state, not only the order currently on screen. If an external sale offsets the purchase, the account may be flat while this order remains correctly recorded as partially executed and cancelled. Erasing its fills to match the net position would destroy the ability to explain how the account became flat.
For risk decisions during uncertainty, distinguish confirmed exposure from possible additional exposure. After the first fill, the client knows 4,000 EUR are purchased and that an unresolved remainder may still execute. A conservative operating policy can restrict new dependent actions until the uncertainty is resolved. The precise response belongs to the system’s risk specification; the lifecycle’s job is to supply truthful quantities and uncertainty, rather than hiding them behind a single optimistic label.
Restart by reconciling evidence, not by resending intentions
Assume the process stops after recording fill-C and its cancellation request, before receiving the final acknowledgement. On restart, the durable ledger shows 4,000 EUR filled and cancellation unresolved. The broker’s eventual history contains both fills and the cancellation. Recovery should discover those facts before allowing the old intention to generate another purchase.
Use three distinct views: the stored local ledger, a broker snapshot with an identifiable boundary, and the remote events needed to bridge the gap. Compare identifiers and quantities, apply previously unseen events exactly once, and rebuild projections. A snapshot is a boundary, not a replacement for all history. It may show the final order state while omitting the detailed execution path needed for average price, attribution or investigation.
OANDA’s best-practices guide describes obtaining an initial account snapshot and retaining its transaction identifier for subsequent updates. Its transaction endpoints include retrieval after a supplied transaction identifier. These are examples of documented recovery facilities, not a universal algorithm for every broker or a guarantee that a live stream replays disconnected history.
For an independent hypothetical recovery fixture, suppose local history is complete through cursor 40, the next three relevant remote events have identifiers 41, 42 and 43, and the fetched snapshot represents the state through 43. Events 41 and 42 contain our two fills and 43 contains cancellation. If constructing the current projection from that snapshot, do not apply the same effects again as though the snapshot preceded them. Historical ingestion and current-state advancement need coordinated boundaries.
If reconstructing from the earlier local state instead, apply the missing events according to the provider’s ordering contract and compare the resulting state with the snapshot. Save the new cursor only when the events and their accounting effects are durable. Advancing it first could permanently skip an event after another crash. Saving events without advancing it is recoverable when deduplication works.
Recovery is complete when the views agree for a known boundary. In this example that includes 7,000 EUR filled, zero active remainder, 3,000 EUR cancelled and quote consideration of 7,700.6 USD. If one view disagrees, retain the discrepancy and restrict dependent actions rather than guessing which number is convenient.
Replay failures that a smooth demo will never show
A useful test starts with our exact two-fill history and a declared expected result. Normal delivery should produce 7,000 EUR filled, 3,000 EUR cancelled, zero leaves and 7,700.6 USD of quote consideration. Then change the delivery conditions while preserving the business events. Duplicating fill-C, delivering fill-D after cancellation acknowledgement or restarting before the acknowledgement should still converge to that result without sending an extra business order.
The intermediate assertions matter too. At offset 190 in the original timeline, the detailed fill ledger should remain short of the reported cumulative total by 3,000 EUR. It should not claim a fully reconciled average based on the first fill alone. At offset 210, receiving fill-D should close that discrepancy while keeping the order cancelled. These checks verify what the client knows, not just what the final spreadsheet eventually says.
Test conflicting evidence, not only missing messages. Replay an event identifier with a different quantity, deliver a stale acceptance after the terminal state, and supply a snapshot whose filled total disagrees with the event ledger. The expected response is an observable reconciliation fault or controlled unresolved state. Silently choosing the largest quantity or the latest received label is not a general solution to contradictory business evidence.
Additional fixtures should exercise rejected creation, rejected cancellation, unknown creation outcome, replacement during a fill, and a snapshot boundary that overlaps downloaded history. Crash after persisting an event but before updating its projection, then crash at the reverse boundary in a deliberately faulty implementation. These tests reveal whether durability and deduplication are actually coordinated. A happy-path simulator will not expose the difference.
Paper trading and replay are useful for these investigations, but their scope must be explicit. A local replay can prove that the application handles a constructed message sequence consistently. A broker’s practice environment can exercise its documented interface under the conditions available there. Neither establishes that production execution, partial-fill behaviour, timing or failure modes will be identical. Keep a contract-specific checklist of what has actually been exercised, and leave unsupported capabilities unclaimed rather than treating a smooth demonstration as evidence of every possible lifecycle.
The final handoff should explain both outcome and certainty
A useful terminal record for order-B would show the original intention to buy 10,000 EUR, the two unique fill identities and their amounts, the retirement of the 3,000 EUR remainder, and the reconciliation boundary that establishes agreement. The readable summary can say “cancelled after 7,000 EUR filled.” That phrase answers much more than “cancelled” because it preserves the economic effect alongside the order’s terminal state.
The record should also distinguish effective event times from when the client learned them. In our example, fill-D occurred at offset 145, cancellation became effective at 170, the cancellation acknowledgement arrived at 190 and the fill report at 210. A reviewer can therefore explain the apparently late trade without inventing a broken cancellation or ignoring the period when local details were incomplete.
Completion includes resolving the known discrepancy. It does not require pretending that later corrections are impossible. An explicit correction, if the provider supports it, should create new linked evidence and revise the relevant accounting projection. It should not be confused with the ordinary cancellation request discussed here. Keeping that distinction protects the meaning of both the original fills and any later adjustment.
The same record helps someone investigate a genuinely inconsistent outcome. If a fill’s effective event time appears after confirmed cancellation, examine clock precision, sequence references, the counterparty’s contract and any correction history. Do not assume it is the same harmless delivery race as our example. The purpose of preserving evidence is to distinguish those cases, not to explain away every contradiction.
The system should report what happened and how securely it knows that. A signal, a submitted request, an accepted order, a fill and a reconciled account are connected stages with different evidence. Following those stages carefully makes a robot’s behaviour inspectable even when the network supplies an untidy story. It also makes the limits of a demonstration clear: observing a signal is only the beginning of the operational question.
Primary sources
The cited FIX Trade specification is dated August 2019; the order-state-change document is dated July 2020. The OANDA order, transaction and recovery documentation was consulted on 2026-11-29 without assigning an unverified publication date. The calculations, identifiers, clocks and test fixtures here are original hypothetical examples, not reported broker results.
Use the TradeAndRoll demo to distinguish a robot’s proposed action from the execution and reconciliation evidence an operational system would need.



