A timed-out order request does not mean the order failed.
The broker may have accepted it and lost the acknowledgement on the way back. A blind retry can then create a second live order. For an unattended trading system, the problem is not simply whether an HTTP call succeeded. It is whether the order intent has one durable identity, whether the broker can recognise repeats, and whether the system can recover the order's actual state after an ambiguous response.
What order idempotency guarantees
Idempotency means that repeating the same submission does not create another order. The usual mechanism is a client-generated identifier sent with the request. The broker stores that identifier and, when it receives a repeat within its supported scope and retention period, returns the original order or its current status instead of placing another one.
Do not assume that a field called client order ID provides this guarantee. Some APIs use it only as a searchable label. Others enforce uniqueness per account, trading day, instrument or open-order set. Some reject a duplicate identifier rather than returning the first order.
Check the documented scope, retention period, character limits and behaviour after a partial fill. If the API does not promise deduplication, treat the identifier as a lookup aid, not a safety mechanism.
Keep three identities separate:
- Intent ID: a stable identifier for one desired trade, created before sending the request.
- Submission ID: an identifier for a particular API attempt, useful for logs and tracing.
- Broker order ID: the identifier returned by the broker after acceptance.
Retries of the same unchanged intent should reuse the same broker idempotency key where supported. A deliberate replacement, such as changing the limit price after a cancellation, is a new intent or a clearly linked revision. Reusing an old key for a changed payload can cause the broker to return the old order, reject the request or apply behaviour that differs by platform.
Even with a broker-side key, exactly-once execution is not a property a client can create by itself. The network can fail between acceptance and acknowledgement.
The practical target is at-most-one accepted order per intent, plus a reconciliation process that resolves uncertainty. A review of API behaviour, including through broker execution tooling, should test those semantics rather than rely on a successful response example.
Price the failure paths
Retry policy has costs on both sides. Retrying too quickly can create rate-limit responses or duplicate exposure. Waiting too long can leave a strategy underfilled or holding stale risk.
The table gives typical market and implementation planning ranges, not audited results for a particular broker. Latency and timeout rates vary with venue, network location, account permissions and market load. Measure them in the environment where orders will run.
| Measure | Typical range | Cost or design implication |
|---|---|---|
| Order acknowledgement latency | About 50-300 ms at p50; 0.5-3 s at p99 | Set a timeout from observed tail latency, not the median. A short deadline creates more ambiguous submissions. |
| Ambiguous submission responses in routine operation | Typical planning range: 0.01%-0.5% of attempts; incident periods can exceed 1% | At 1,000 submissions, that routine range implies roughly 0.1-5 cases to reconcile, not necessarily failed orders. |
| First retry delay | Typical implementation range: 100-500 ms, with jitter | Immediate retries can add load during an outage. Backoff reduces request pressure but delays recovery. |
| Retry ceiling | Typical implementation range: 2-4 attempts before reconciliation or escalation | More attempts do not resolve an unknown order state. They can worsen a broker incident. |
| Idempotency-key retention | API-specific; a typical documented range is 24 hours to 7 days, while some APIs offer no deduplication guarantee | Do not replay a stored request after expiry without checking order state first. |
Translate duplicate exposure into a number the risk layer can use. For a typical illustrative limit order of 100 shares at $50, one accidental duplicate adds $5,000 of gross notional before considering fills, fees or price movement. That is not the same as a $5,000 loss, but it can double intended exposure. A useful per-event cost model is: duplicate filled quantity multiplied by the difference between the execution price and the intended reference price, plus fees and any hedge or liquidation cost.
There is also a missed-trade cost. If a retry is delayed while the market moves, compare the eventual fill with the price available when the intent was created. For liquid instruments, even a 1-5 basis point move on $5,000 of notional represents about $0.50-$2.50 in price difference. These are illustrative calculations using a typical small order size, not a forecast of slippage. For larger orders or wider markets, the amount scales with notional and liquidity.
Build retries as a state machine
Represent each intent with explicit states rather than a single success flag. A minimal model might include created, submitted, unknown, accepted, part-filled, filled, rejected and cancelled.
Persist the intent and its key before making the network call. On restart, the process must be able to resume from stored state rather than invent a new order identity.
- Create and persist the intent. Store account, instrument, side, quantity, order type, price constraints, strategy version and a unique intent ID. Record a canonical payload hash so a retry cannot silently change the order parameters.
- Submit once with a stable key. Save the request timestamp and submission ID. Set a request deadline based on measured API latency, but do not interpret a client-side timeout as rejection.
- Classify the response. Retry clear transient failures such as a connection reset before transmission only when the client can establish that no request was sent. For a timeout after transmission, mark the state unknown. Treat validation errors and other permanent 4xx responses as failures to correct, not as retry signals. Respect a 429 response and its Retry-After value.
- Resolve unknown state before resubmission. Query by the stable client ID or broker order ID. If the broker supports idempotent replay, repeat the identical payload with the same key within the documented window. If it does not, use order and fill queries before deciding whether a new submission is safe.
- Update from executions, not just order status. A partially filled order remains exposure. Calculate remaining quantity from confirmed fills, and do not submit the original full quantity again. On cancellation or replacement, wait for the relevant state transition and link the new order to the original intent.
- Stop at a bounded retry budget. Use exponential backoff with jitter, for example a typical sequence starting around 200 ms and capped around 2 seconds, subject to rate limits and strategy urgency. After 2-4 attempts, move to reconciliation or a defined fail-safe instead of continuing indefinitely.
There is a direct trade-off between freshness and certainty. A fast strategy may tolerate only a short delay before cancelling an unfilled order, while a slower strategy can afford a longer query window.
Neither should turn an unknown submission into a fresh order without checking position and open-order state. Set a maximum unresolved duration and define what the agent does when the broker remains unavailable, such as block new risk or switch to a restricted mode.
Test recovery, not just successful requests
Test at the boundary where the client and broker can disagree. A happy-path response proves little about retries. Build fault-injection cases that drop acknowledgements, delay responses past the client deadline, return duplicate-key errors, throttle requests and restart the process after sending but before recording a response. Include partial fills and cancellation races. Keep a record of request payloads, intent IDs, broker IDs, response codes, timestamps and fill events so each discrepancy can be reconstructed.
- Send the same intent twice with the same key. Verify the broker's actual response and confirm that only one order is live.
- Send the same key with a changed quantity or price. Confirm whether the API rejects it or returns the original order, and make the client handle that result explicitly.
- Drop the acknowledgement after broker acceptance. Restart the agent and check that it finds the existing order rather than placing another.
- Simulate a partial fill followed by a timeout. Verify that any remaining quantity calculation uses confirmed fills.
- Expire the documented key-retention window in a test environment. Confirm that the system reconciles before replaying.
Track ambiguous submissions per 1,000 intents, duplicate live orders, time to resolve unknown state, retries per intent, partial-fill discrepancies and the share of orders reconciled without manual intervention. Segment the numbers by broker, order type and market session. A weekly aggregate can hide a failure concentrated in opening minutes or a single API route.
Paper trading is useful for checking state transitions and process restarts, but it may not reproduce live rate limits, fill timing or broker deduplication rules. Compare the simulated order path with the broker's documented behaviour and keep live exposure capped while validating the integration. The Agentic Trading Index platform evaluations can help frame that review, but the production system still needs its own measured latency and recovery tests.
Before increasing order size, inspect one operational metric: the number of intents that remain in an unknown state for longer than your system's recovery limit over the last 30 days.
Frequently Asked Questions
What does idempotency mean in order placement?
It means repeated submissions of the same intent do not create multiple orders, when the broker supports and enforces that behaviour. Use a stable key and verify its scope, retention period and handling of changed payloads.
Should an order be retried after an API timeout?
Not until the system checks whether the broker accepted it. Query using the client order ID or another supported lookup method. If the broker guarantees idempotent replay, retry the identical request with the same key within its documented window.
How many times should an automated trading system retry an order?
A bounded policy of roughly 2-4 attempts is a typical implementation range, with backoff and jitter. After that, reconcile the order state or apply a defined fail-safe instead of submitting indefinitely.