In nearly every unattended trading setup, the agent's position and the broker's position diverge briefly. A fill arrives late, a process restarts between events, or a manual close changes the account while the agent is offline.
The problem is not that a mismatch can happen. The problem is allowing the agent to trade on a position it has not verified.
Use this checklist over the next five trading days. The objective is a repeatable reconciliation loop: collect broker evidence, compare it with the agent's ledger, classify any difference, then either repair state or stop new exposure. Do not treat a matching position total as proof that orders, fills and risk limits also match.
Define what counts as the source of truth
Write down which record wins for each field. The broker's confirmed executions and current position snapshot are authoritative for filled quantity.
The agent's order journal is useful for intent and local processing history, but it cannot prove that an order filled. Open orders are a separate state: a working order can change the position after a snapshot is taken.
Before comparing records, normalise them. Use the broker account, instrument identifier, position side, quantity unit and trading session as part of the key. Convert contracts, shares and fractional quantities consistently. For futures, include contract expiry; for options, include the full contract identifier. Check whether the broker reports net positions or separate long and short lots.
Choose a consistent quantity precision. If fractional shares are supported, compare using the instrument's allowed precision rather than rounding both sides to whole units. Keep monetary exposure separate from quantity reconciliation. A correct share count can still have stale marks, currency conversion or multiplier data.
Set an explicit policy for external activity. Either prohibit manual orders in the agent's account, ingest them as broker-originated events, or detect them through snapshots and pause trading until reviewed. Silent assumptions about human intervention are a common source of recurring drift.
Run the checks this week
Day 1: build a comparable ledger
For every order, retain a durable record of the client order ID, broker order ID, instrument, side, requested quantity, cumulative filled quantity, leaves quantity, status and timestamps. Store each execution separately with its execution ID, quantity, price and broker event time. A single mutable order row is not enough to reconstruct what happened after a restart.
Make event handling idempotent. Persist the broker execution ID before applying its quantity to the position, or use a transaction that commits both together.
On replay, a previously applied execution must not be counted twice. Record event time and receive time separately so you can distinguish a late fill from a delayed consumer.
At the end of the first session, compare a fresh broker snapshot with positions rebuilt from executions. Include open orders in the review, but do not add their leaves quantity to the filled position. Calculate the expected position change separately so the risk layer can account for possible fills.
Days 2 to 5: exercise failures and recovery
Test at least these cases in paper trading or a controlled test account:
- A partial fill followed by a cancel, with the final execution arriving after the cancel acknowledgement.
- A duplicate execution event, then a process restart and replay from the last durable checkpoint.
- A dropped websocket connection while the broker continues to fill an order.
- An order rejected or cancelled at the broker while the agent still believes it is working.
- An external position change, if the account permits orders outside the agent.
For each case, record the broker snapshot, event stream, agent position and recovery action. Confirm that a reconnect triggers a fresh snapshot and an order-state refresh, not just a websocket subscription. A paper-trading environment such as Agentic Trading Index's agentic trading tools can help exercise event-handling paths without risking live capital, but verify broker-specific behaviour separately.
Do not send corrective orders as the first response to every mismatch. If the agent's position is wrong because an execution was missed, a new order can double the intended exposure. Freeze new orders for the affected instrument, fetch executions since the last confirmed sequence or timestamp, rebuild the ledger, then compare again.
Classify mismatches before taking action
Measure the mismatch and its age
Calculate the signed quantity difference as broker position minus agent position. Keep the absolute difference for thresholds, and preserve the sign for diagnosis. Measure age from the oldest unresolved event or last successful snapshot. A one-share difference for a large liquid equity may be immaterial; the same difference in a small options position may be the entire intended exposure.
The figures below are typical market ranges for planning a reconciliation loop, not service guarantees. Broker limits, asset class, account type and streaming quality can move them substantially.
| Check | Typical market range | What to inspect | Initial response |
|---|---|---|---|
| Fill event delivery | 100 ms to 5 s | Broker event time versus receive time | Allow a short settling window, then query executions |
| Position polling cadence | 1 to 5 s while actively trading | Snapshot timestamp and API rate limits | Back off on throttling; do not assume an old snapshot is current |
| Routine snapshot interval | 1 to 15 min | Position, open orders and recent executions | Increase frequency during active order flow if limits permit |
| Stale-state trigger | 5 to 30 s | Time since confirmed broker state | Block new risk until a fresh query completes |
Choose a recovery action by cause
Use a small set of outcomes, and log which one was selected:
- Late event: wait briefly, query executions and apply any missing fills once.
- Duplicate event: discard it by execution ID, then verify that the rebuilt quantity matches the broker.
- Unknown broker order: stop new orders for the instrument and identify its origin before cancelling anything.
- Unexplained position difference: pause new exposure, refresh executions and snapshots, and escalate if the broker evidence does not explain it.
- Broker query failure: mark state stale and fail closed for orders that could increase exposure. A retry is not confirmation.
Closing a position to force agreement is not a reconciliation method. It is a new trading decision with spread, fees and possible slippage. If reducing risk is necessary, make that an explicit, separately logged policy with limits on order size and repeated attempts.
Make reconciliation a production control
Run reconciliation at startup, after every reconnect, after order timeouts, and on a recurring schedule while the account is active. A periodic check catches silent drift; event-driven checks reduce the time the agent trades on stale state.
Keep both. A broker snapshot and an execution history answer different questions, so fetch both where the API supports it.
Expose operational measures by account and instrument: last successful snapshot time, mismatch quantity, mismatch age, unprocessed execution count, duplicate event count, and time spent in a trading pause. Alert on a growing mismatch or repeated repair, not merely on a single transient difference. Retain enough raw broker responses and event IDs to reconstruct the incident.
Set the control so a failed reconciliation cannot silently become permission to trade. For example, allow risk-reducing orders under a narrow policy while blocking orders that increase exposure. Set a maximum stale-state duration and define who or what can clear the pause. A human approval path can be a fallback, but the default recovery should not depend on someone noticing a log line.
Review the checklist after a broker API change, a change to order handling, or a new asset class. Then run it again in paper trading before deploying the same code path live.
Check the configured maximum unexplained position difference in the live risk gate today. The number to verify is 0.
Frequently Asked Questions
How often should a trading agent reconcile positions?
Reconcile at startup, after reconnects and order timeouts, and periodically during active trading. Typical polling intervals range from 1 to 5 seconds while orders are active, subject to broker API limits. Use a fresh snapshot and execution history when checking a mismatch.
Should the broker or the agent be the source of truth for position?
Use broker-confirmed executions and position snapshots as the authority for filled quantity. Keep the agent's ledger to track intent, event processing and recovery history. Compare open orders separately because they may change the position later.
What should an agent do when its position does not match the broker?
Pause new exposure in the affected instrument and fetch fresh executions, open orders and a position snapshot. Rebuild the agent ledger using unique execution IDs so replayed events cannot double-count fills. Do not place a corrective order until the cause is understood.