Operator A receives a fill notification, updates its internal position and carries on. Operator B distrusts notifications, queries the broker and finds a partial fill that the agent missed.
A then sizes its next order against a position that does not exist; B risks trading twice if its query is stale. Position reconciliation is the mechanism that prevents either assumption from becoming an unobserved exposure.
For an unattended system, the choice is not whether to trust the agent or the broker absolutely. It is how to combine their different records, detect disagreement and decide what the software may safely do next.
Settle what each state represents
Agent state should describe intent and strategy context: target exposure, strategy identifier, pending actions and the decisions that led to them. Broker state describes what the account has actually accepted and executed: orders, fills, open positions, cash and buying power.
Keep both. Replacing agent state with a broker snapshot can erase intent; treating the agent's ledger as proof of execution can invent exposure.
Use the broker's executions to build an independent position ledger where possible. Compare that ledger with the broker's reported positions as a second check.
Position quantities alone do not explain a mismatch: inspect open orders and recent fills too. A buy order may be partially filled, cancelled after a fill, or still working while the agent has already timed out.
Define the comparison key before writing reconciliation logic. It usually includes account, instrument, product type and position side.
Netting accounts combine buys and sells into one signed quantity. Hedging accounts may retain separate long and short legs. Mapping both to a single number can hide a real exposure difference.
Compare the reconciliation designs
There are three common designs, with different failure modes.
- Periodic snapshots: query positions and open orders on a schedule. This is straightforward to build and recovers from missed events, but drift can remain unnoticed between polls. A slow or rate-limited endpoint can also return an old view.
- Event-led updates: update local state from order and execution notifications. This gives low latency and reduces repeated queries. It depends on handling duplicate, delayed and out-of-order messages, plus reconnecting after a dropped stream.
- Hybrid reconciliation: process events continuously, then compare with broker snapshots on a timer and after reconnects, timeouts or uncertain order submissions. It costs more to implement, but gives the system a recovery path when an event is lost.
Event-led is not the same as reliable. A websocket can disconnect after an exchange fill and before the notification reaches the agent.
Snapshot-only is not automatically safe either: a position endpoint may lag the execution endpoint or omit pending orders. A hybrid design narrows both gaps, provided it records when each source was last refreshed.
For most unattended order placement, hybrid is the practical default. A small account polling every 5 to 30 seconds may be sufficient if the strategy tolerates that detection delay. A fast strategy needs event handling and a shorter reconciliation interval, but still needs a snapshot after every stream recovery.
Make mismatches actionable
Not every difference means the position is wrong. It can reflect a fill arriving before the position endpoint updates, an agent restart that lost its local checkpoint, or a symbol mapping error. The system should classify the discrepancy before taking action.
Persist broker order IDs and your own stable client order IDs. Make order submission idempotent where the API allows it.
After a request times out, query by client ID before resubmitting: the broker may have accepted the first request even though the response never arrived. Reconstruct quantities from executions using signed fills, and preserve fill IDs so replaying a stream does not count the same execution twice.
Separate detection from correction. For example, pause new orders for the affected instrument while checking recent executions and open orders.
Do not automatically flatten a position just because the local quantity and the snapshot differ. Flattening can turn a temporary reporting delay into a real trade, incur fees and create a second mismatch.
Useful mismatch categories include:
- Quantity difference, after accounting for signed fills and account netting rules;
- Unmatched working order or cancellation in progress;
- Unknown broker order or fill, which may indicate manual trading or another process;
- Stale snapshot, broken stream or unresolved instrument mapping.
Give each category a response. Some can trigger a retry or a fresh query.
Unknown orders should usually block new risk until identified. Manual activity needs an explicit policy: either include it in the strategy's available exposure or treat the account as out of scope.
Budget for detection and recovery
The figures below are typical ranges for one account, one venue and a modest service using an existing broker adapter. They are planning estimates, not broker prices or audited results. Multi-account deployments, complex products and strict availability requirements can increase both build time and operating cost.
| Approach | Typical build effort | Typical monthly infrastructure | Typical drift detection |
|---|---|---|---|
| Periodic snapshots | 8 to 20 engineer-hours | $5 to $50 | 5 to 60 seconds, depending on polling |
| Event-led updates | 20 to 60 engineer-hours | $10 to $100 | Under 1 to 5 seconds while the stream is healthy |
| Hybrid | 30 to 80 engineer-hours | $15 to $150 | Under 1 to 10 seconds, with recovery checks |
Infrastructure estimates cover typical modest compute, logging and monitoring. They exclude market data subscriptions, broker charges, engineering salaries and the cost of incident response. The hidden cost is often not polling. It is incomplete history: without durable order and execution records, recovery after a restart becomes manual investigation.
Test the failure paths as well as the normal flow. A paper-trading environment can exercise duplicate notifications, partial fills, rejected cancels and agent restarts before live orders are involved. The Agentic Trading Index paper trading service starts at $9.99 a month; check that any test environment exposes the state transitions the production adapter needs to handle.
Use a bounded recovery loop
Run reconciliation at startup, on stream reconnection, after an order timeout and on a regular schedule. Record both the broker's event time and the time the agent received it. If timestamps are missing or unreliable, sequence numbers and fill IDs can still help identify gaps. Keep a durable checkpoint so a process restart does not reset the history needed to distinguish a new fill from a replay.
A practical checklist for each reconciliation cycle:
- Load the last durable checkpoint, pending client order IDs and local execution ledger.
- Fetch recent orders, executions and positions, using a time overlap to catch delayed records.
- Deduplicate fills, then rebuild the local broker-derived quantity for each account and instrument.
- Compare it with the broker snapshot and agent target, accounting for open orders and netting rules.
- Classify mismatches, record the evidence and pause only the affected risk where possible.
- Retry safe reads. Never resubmit an uncertain order until its broker status has been checked.
- Resume only when the discrepancy is explained or an explicit operator policy permits trading.
Measure time to detect drift, time to classify it, unresolved mismatch count and the number of orders submitted while state was uncertain. A low average detection delay can still conceal a dangerous tail, so track the longest interval and the rate of unexplained differences. Keep reconciliation logs with request IDs, timestamps, quantities and decisions, while avoiding credentials and unnecessary personal data.
This advice does not apply to an alert-only agent that never submits, cancels or manages orders; it has no broker position state to reconcile.
Frequently Asked Questions
How often should a trading agent reconcile positions?
Reconcile at startup, after reconnecting to a broker stream, after an uncertain order response and on a regular schedule. A 5 to 30 second interval is a typical starting range for slower strategies, but the right interval depends on how much undetected exposure the system can tolerate.
Should the broker or the agent be the source of truth?
Use broker executions and positions to establish what has traded, and agent state to retain intent and strategy context. Compare them rather than overwriting one with the other. Check open orders and recent fills before acting on a quantity mismatch.
Should an agent automatically close a mismatched position?
Not by default. A mismatch can come from a delayed snapshot, a partial fill or an unknown order, and an automatic close may add unwanted exposure or fees. Pause affected orders, gather current broker evidence and apply a defined correction policy.