FREE FINANCIAL EDUCATION
Idempotent order recovery
Treat a submission timeout as unknown state rather than proof of failure.
What you will learn
Prerequisites: Understand uncertain acknowledgements, durable request identifiers and authoritative broker reconciliation.
- Treat a submission timeout as unknown state rather than proof of failure.
- Separate retrying one intent from creating a new order intent.
- Recompute residual desired quantity from reconciled fills after cancellation.
Mechanism and decision rules
An idempotent operation can be retried under its documented contract without repeating its economic side effect. For order handling, a client identifier is useful only if the service’s actual semantics support deduplication or reliable lookup; merely putting a unique string into a request does not make every broker endpoint idempotent. Persist the intended order and its identity before transmission so a restart can distinguish an unresolved intent from a new decision.
After a timeout, query or reconcile the original order and executions using the documented mechanism. Preserve pending exposure while its status is uncertain. If a change of intent requires cancellation and replacement, wait for authoritative terminal state and account for intervening fills before sizing the new order. Message deduplication and request deduplication are separate responsibilities: one protects the local ledger from replayed fills, the other prevents duplicate orders from being created.
Worked example · synthetic data
A hypothetical strategy wants total holdings of 100 units and sends order R17 for 100. Its acknowledgement is lost. Reconciliation finds 40 filled and 60 still live. A fresh 100-unit order would permit up to 200 total units if both complete; the correct current state already covers the desired 100. Later the strategy requests cancellation and another 10 units fill before the final cancel confirmation. Reconciled holdings are now 50 and live leaves zero. If the original 100-unit target still applies, a new authorized intent should request only the remaining 50, under a new identity.
Failure modes and limits
Reconciliation can itself be delayed, and different endpoints may expose snapshots taken at different times. Do not declare flatness or retry success without checking the resulting position and live orders. Idempotency keys may expire or reject changed parameters, and a reconnect can replay old executions. Define an explicit unresolved-state mode that blocks conflicting new exposure while preserving the information needed for recovery; no local mechanism guarantees action during a service outage.
Practice case
A new strategy target is 60 units. An uncertain 60-unit request is later found to have 25 filled and 35 live. How much additional quantity should be submitted immediately? If cancellation later completes after another 10-unit fill, what residual quantity would a new intent require to reach the unchanged target?
Reveal the worked answer
Submit no additional quantity while the original 35 remain live: confirmed plus pending exposure already totals 60. After the extra 10-unit fill and confirmed cancellation, holdings are 35 and live leaves zero. A new intent for 25 would reach the unchanged target. Reusing a key with changed parameters or submitting that residual before reconciliation could violate the service contract or overshoot the target.
Check your understanding
Sources and next steps
The lesson, calculations and synthetic cases are original educational material. References explain underlying contract or chart conventions; none validates the profitability of a trading rule. Actual contract specifications, settlement obligations and charges must be checked before trading.
Explore OHLCV data in the chart lab · Explore volume-at-price and TPO data · Practice library
