Why position reconciliation starts with the broker
One missed E-mini S&P 500 contract can expose an unattended account to $500 of gross profit or loss over a 10-point move, before fees. The contract multiplier is $50 per point. If the agent believes it is flat while the broker holds one contract, its internal risk limits are working from the wrong position.
Position reconciliation compares the agent's recorded state with the broker's observed state, then decides whether trading can continue. It is not just a startup check. Run it after reconnects, order events and scheduled intervals, and before actions that could increase exposure. The broker's positions and executions are the authority for what is actually held. Agent intent remains useful for diagnosing how the mismatch happened.
Keep three views distinct: desired position, locally projected position and broker-reported position. Collapsing them into one number makes a partial fill or delayed event look like a simple state update. That is how an agent can submit a second order to correct a position that has already changed at the venue.
Keep intent, fills and broker positions separate
Represent positions by stable instrument identifiers, not display symbols alone. Store account, venue, contract or instrument ID, signed quantity, multiplier and currency. A quantity of 2 and -2 should have a clear meaning, and corporate actions, futures rolls or option expiries must not silently map to the same instrument.
Maintain an order ledger alongside the position ledger. Each order needs its client order ID, broker order ID, requested quantity, cumulative filled quantity, remaining quantity, status and last update time.
Record executions by unique execution ID where available. A retry or duplicate stream message must not add the same fill twice.
For each instrument, calculate expected exposure from the last trusted broker snapshot plus unique executions received since that snapshot. Compare that result with the newest broker position. Do not add an order's full requested quantity to a position: only fills change the position. Keep open orders visible because they may still execute while a mismatch is being investigated.
Useful invariants include:
- Filled quantity never exceeds order quantity unless the broker explicitly reports a correction or bust.
- A repeated execution ID changes neither cumulative fills nor position.
- Open order quantity equals original quantity less cumulative fills, subject to broker amendments.
- Every position record has an observation time and source, not just a quantity.
Build a snapshot and event reconciliation loop
Broker snapshots and streaming events can cross in flight. A position snapshot may include a fill whose execution event arrives afterwards. If the agent applies that event on top of the snapshot, it double-counts the fill. Use broker sequence numbers or event cursors when available. Otherwise, capture request and response times, buffer events during the snapshot, and use broker order and execution records to establish which fills are already reflected.
A practical cycle is:
- Pause new risk-increasing orders for the account or affected instruments.
- Fetch positions, open orders and recent executions. Follow every page of paginated results.
- Record response timestamps, broker cursors and any request errors.
- Deduplicate executions, reconcile order status, then compare calculated and broker-reported quantities.
- Resume only when the state is consistent or an explicit exception policy permits limited trading.
After a connection drops, do not assume the event stream will replay everything. Query a time range that overlaps the last confirmed cursor, deduplicate it, then start streaming from a current cursor if the API supports that sequence. If the API offers no reliable cursor, keep the account in a restricted state until snapshots and order history agree.
Poll rate is a trade-off. A one-second full-account snapshot may exhaust request limits or add load without improving safety if responses take longer than a second.
A common design is event-driven updates plus a full snapshot every 30 to 60 seconds, with immediate snapshots after reconnects and ambiguous order outcomes. Measure actual latency and rate limits on the chosen broker.
Set drift thresholds and price the exposure
Define drift in units that match the instrument. For shares, one share may be material for a small account but negligible for a large one. For futures, one contract can create substantial delta. For options, matching contract count alone misses changes in delta and multiplier. Set both an absolute tolerance and a notional or risk limit.
For example, a policy might tolerate a temporary difference of one share only when notional is below $100, while treating any futures contract mismatch as a hard stop. A 0.5% notional discrepancy can be a useful investigation trigger, but it should not replace instrument-specific limits. Cancel or hold risk-increasing orders while the difference is unexplained.
The table gives illustrative gross exposure for a $50,000 position if an unrecognised position moves against the account. These are broad typical intraday move ranges, not forecasts. Market behaviour varies by asset, session and volatility regime, and a favourable move can produce a gain rather than a loss.
| Unreconciled interval | Illustrative typical move range | Gross P/L exposure on $50,000 |
|---|---|---|
| 1 to 5 minutes | 0.02% to 0.10% | $10 to $50 |
| 5 to 15 minutes | 0.05% to 0.30% | $25 to $150 |
| 15 to 60 minutes | 0.10% to 1.00% | $50 to $500 |
These figures estimate exposure, not total trading cost. Fees, spread, slippage and the cost of flattening can add to the result.
Size thresholds using a stressed move as well as ordinary conditions. A mismatch that is safe during a quiet session may be unacceptable near an opening auction or scheduled announcement.
Choose a repair policy that cannot compound errors
Never let the agent automatically trade the difference just because two quantities disagree. First determine whether an open order, delayed fill, correction, corporate action or stale snapshot explains it. A corrective market order can double the exposure if the original order is still live or the broker's position query has not caught up.
Classify mismatches and assign actions. A small, explainable delay can trigger a short retry. An unknown execution or an unavailable position endpoint should freeze new risk. A confirmed position difference may be repaired only after outstanding orders are cancelled or accounted for, and after the chosen broker state is fresh enough for the policy.
- Soft drift: log the difference, block orders that increase exposure, and re-query after a short delay.
- Hard drift: cancel eligible open orders, disable new orders and alert an operator.
- Uncertain state: preserve the last known broker data, mark it stale and do not infer that the account is flat.
- Confirmed mismatch: require an explicit repair rule, quantity cap and audit record before placing a corrective order.
Log the before and after quantities, order IDs, execution IDs, snapshot times, reason code and action taken. A paper-trading environment is a practical place to test reconnects and delayed events before live exposure; Agentic Trading Index offers agent paper trading from $9.99 a month. The test should inject duplicate fills, partial fills, rejected orders and a snapshot that arrives out of sequence, not just verify the happy path.
Run this checklist before unattended orders
Use the checklist for launch, deployment changes and recovery from a broker or network incident:
- Confirm that account and instrument identifiers map to the correct broker records.
- Verify position quantity, multiplier, currency and observation timestamp.
- Fetch all open orders and recent executions, including every result page.
- Deduplicate executions and test that replaying an event leaves state unchanged.
- Calculate position from the trusted snapshot and subsequent unique fills.
- Apply absolute and notional drift limits for each instrument class.
- Test that stale data, API errors and unresolved orders block risk-increasing actions.
- Test a repair only after the original order state is known, and cap its size.
- Confirm that alerts and audit logs include enough IDs and timestamps to reproduce the decision.
Run these tests in the same code path used for live orders. If reconciliation logic has not been exercised against event loss and replay, start by adding a read-only reconciliation report this week.
Frequently Asked Questions
How often should a trading agent reconcile positions?
Use broker events for prompt updates and run full snapshots on a measured interval, often every 30 to 60 seconds. Reconcile immediately after reconnects, ambiguous order outcomes and other events that can leave local state incomplete.
Which state is authoritative, the agent or the broker?
The broker's reported positions and executions determine what the account holds. The agent's intent and projected position help explain how it reached that state, but they do not override broker records.
Should an agent automatically correct a position mismatch?
Only after it has ruled out open orders, delayed fills, duplicate events and stale snapshots. If the mismatch remains unexplained, freeze risk-increasing orders and escalate rather than placing a blind corrective trade.
How can I prevent duplicate fills from corrupting position state?
Store executions by a stable broker execution ID and make event handling idempotent. If the broker does not provide a reliable identifier, compare order history and cumulative filled quantity before applying an update.