One operator sees a broker position that differs from the agent ledger and stops new orders until the execution history catches up. Another sees the same difference and immediately sends a trade to flatten it.
The first risks carrying unwanted exposure for longer. The second risks doubling the position if the broker report was stale or an earlier order is still working. Position reconciliation is the process that determines which state is trustworthy, how large the difference is, and what action is safe.
Reconciliation starts with a defined position
Before comparing numbers, define the unit and scope of a position. A value of 3 could mean three shares, three futures contracts, or three lots of a leveraged product. It could refer to one strategy, one account, or the broker's net position across several strategies. A reconciliation system needs the same instrument, account, side, unit, and aggregation rules on both sides.
Keep three concepts separate:
- Target exposure: what the strategy wants to hold after its risk and portfolio rules.
- Agent ledger: the position implied by executions the agent has processed.
- Broker position: the broker's reported exposure for the account and instrument.
Do not compare target exposure directly with broker position and call the difference a reconciliation error. A strategy may deliberately be reducing a position, or an order may be working.
Compare the broker position with the agent ledger first. Compare target with the resulting or expected position separately.
Canonicalise instruments before calculating a difference. Map broker symbols to internal identifiers, account for contract multipliers, and distinguish futures expiries. For options, include expiry, strike, and right. For FX, define whether quantities are base units or lots. A symbol mapping error can look like a large unexplained position even when every fill is correct.
Keep execution state separate from intent
The agent ledger should be built from executions, not from order requests. A submitted order is intent.
An acknowledgement confirms that the broker accepted a request, not that it filled. A fill changes position. Cancellations, rejects, corrections, and busts may change the expected result or require a ledger adjustment.
Persist each execution with a broker execution identifier, order identifier, account, instrument, side, quantity, price, event time, and receipt time. Deduplicate on a stable execution identifier where the API provides one.
If it does not, define a defensible composite key and retain the original payload for investigation. Never assume that a websocket event arrives once, in order, or before the REST response.
On reconnect, obtain a broker position snapshot and an execution history with a sequence number or time cursor. Apply events after the snapshot boundary once, then compare the resulting ledger with the next broker snapshot. If the API cannot provide a consistent boundary, mark the comparison provisional. Replaying a snapshot and a stream without a boundary can apply the same fill twice or omit a fill that occurred during the request.
Keep open orders in the same view as positions. A broker position of zero with a live buy order is not equivalent to a flat account.
Calculate a range of possible exposure from working orders, including partial fills and remaining quantity. A replacement order can overlap the original if cancellation is pending. Those states should block an automatic repair until the broker confirms which orders remain live.
Measure drift by size, age and exposure
For instrument i, calculate signed quantity drift as broker quantity minus ledger quantity. Also calculate absolute drift, and translate it into notional or risk exposure using the contract multiplier and a current price. Signed drift tells whether the agent is long or short relative to the broker.
Absolute drift measures the size of the disagreement. Notional makes a one-share error and a one-contract error comparable in portfolio terms. Track at least these measures by account and instrument:
- Drift quantity and notional: both signed and absolute, with units stated.
- Mismatch age: time since the first confirmed disagreement, not time since the latest poll.
- Snapshot age: time since broker state was received, with a separate event-stream lag.
- Unresolved mismatch duration: seconds or minutes from detection until agreement or an explicitly accepted exception.
- Reconciliation coverage: share of active instruments with a valid broker comparison inside the freshness limit.
Use a tolerance only where the instrument or broker reports fractional quantities, rounding, or delayed updates that make exact comparison unreliable. Set the tolerance in canonical units and in notional terms.
For example, a fractional-share account might permit a very small quantity difference, while a futures position should usually match in whole contracts. A tolerance is not permission to ignore a stale snapshot.
Measure time to detection and time to resolution separately. A five-second detection delay followed by a ten-minute unresolved mismatch is a different operational problem from a slow poll that detects and resolves the difference in one cycle.
Record counts and exposure-weighted totals. A raw count of mismatches can overstate harmless small errors and hide one large position.
Convert mismatch into cost
A mismatch has a potential market cost, but not every disagreement should trigger a trade. Estimate the cost of holding the unexpected exposure over the expected resolution time, then compare it with the cost and risk of repair. Use venue-specific fees and live market conditions where available. The figures below are typical market ranges, not broker quotes or audited results. Actual costs vary by instrument, venue, account, time of day, and order size.
| Instrument or charge | Typical market range | How a mismatch creates cost |
|---|---|---|
| Liquid large-cap equity spread | About 1 to 10 basis points | A forced close and re-entry can cross the spread, before market impact and fees. |
| Major FX pair spread in liquid hours | About 0.1 to 1.5 pips | Repairing an unintended residual can cross the spread; conditions can widen around news or rollover. |
| Liquid index futures spread | About 0.25 to 1 tick | Crossing to remove a contract mismatch adds spread cost and may move the next hedge. |
| Equity order commission | About $0 to $5 per order, before some venue fees | Repeated repair attempts can add fees even when the net position ends unchanged. |
| Futures commission and exchange fees | About $0.50 to $5 per contract per side | Closing and reopening a contract can incur charges on both sides. |
These ranges help set a measurement framework, not a universal repair threshold. Estimate exposure from the actual mismatch: quantity multiplied by contract value, with currency conversion where required. A useful dashboard reports mismatch notional, estimated one-way repair cost, and the potential loss from holding the exposure under a chosen price move. Keep modelled costs distinct from realised execution costs.
For example, if an agent ledger is short 10 shares and the broker reports short 12, the signed quantity drift is minus 2 shares from the agent's perspective. The system should not simply buy two shares if a sell order for two more is still working.
It should first establish whether that order filled, remains open, or was rejected. Cost estimates help prioritise the investigation, but they do not resolve the underlying state ambiguity.
Repair only after state is trustworthy
Use a state machine rather than a single mismatch threshold. A normal sequence is matched, mismatch detected, state validation, repair permitted, repair pending, and matched again. A stale snapshot, missing event cursor, or unresolved order should move the system into an ambiguous state.
In that state, block new risk-increasing orders for the affected instrument or account. Whether to allow risk-reducing orders depends on the broker's order and position semantics.
A repair order must be idempotent at the application level. Persist the repair decision and its unique client order identifier before sending it.
On timeout, query the broker by that identifier or reconcile open orders before retrying. Blindly resending after a timeout can create a second repair order. Apply limits for maximum repair quantity, notional, attempt count, and elapsed time. Send exceptions to an operator or a separately defined safe state when those limits are reached.
Use this numbered checklist for the repair path:
- Confirm that the broker snapshot is fresh and that the event stream has no sequence gap.
- Fetch open orders and pending cancels for the affected account and instrument.
- Rebuild the agent ledger from deduplicated executions through the snapshot boundary.
- Recalculate signed quantity, absolute quantity, and notional drift in canonical units.
- Check that the mismatch exceeds configured tolerances and is not explained by an active order.
- Apply the instrument-specific repair cap and verify that estimated exposure stays within risk limits.
- Persist the repair decision, submit once, and reconcile the resulting execution before declaring success.
Measure repair success as the proportion of authorised repairs that return to a matched state without duplicate orders, and report the distribution of repair duration. A fast average can conceal a small number of long-lived mismatches, so retain median and high-percentile durations, such as the 95th percentile. Also count repairs that were cancelled, rejected, or escalated rather than silently excluding them.
Test the recovery path, not just the happy path
Test reconciliation with event sequences that create ambiguity. Include fills that arrive before acknowledgements, duplicate execution events, out-of-order updates, partial fills followed by cancel, cancel-replace races, rejected orders, broker corrections, and reconnects during active trading.
Compare the final ledger with a known broker state after each test. A test that only sends one order and receives one fill will not exercise the failure modes that cause position drift. Replay captured event sequences with delayed and repeated messages. Inject a stale position snapshot, a missing stream sequence, and a timeout after the broker has accepted a repair order.
Verify that the agent freezes the right scope, does not resend blindly, and can resume only after it has re-established a valid state. Run the same scenarios against paper trading before live deployment. A test environment such as an agentic paper-trading platform can help exercise order and position workflows without risking live capital, but its broker semantics still need to be checked against the intended venue.
Alert on exposure and duration, not every transient event. A practical policy might alert immediately when mismatch notional exceeds a risk limit, and alert when a smaller mismatch persists beyond a short freshness window.
Set thresholds per instrument liquidity and account size, then review false positives and missed incidents from logs. Store the snapshot, execution cursor, open-order view, computed drift, and action taken for each alert. That record makes an unexplained change diagnosable after the fact.
This advice does not apply as written when several strategies share an account, intentionally offset each other, and the broker exposes only a net position. Reconcile broker exposure at account level, then maintain strategy allocations in an internal ledger rather than trying to match each strategy's position to the broker's net figure.
Frequently Asked Questions
What is position reconciliation in automated trading?
Position reconciliation compares the position implied by an agent's processed executions with the broker's reported position. It identifies drift, stale data, or missing events before the agent takes further action.
How often should a trading agent reconcile positions?
Reconcile after reconnects, execution events, order-state changes, and before resuming after a fault. Polling frequency depends on API limits and strategy risk, but the system should also detect stream gaps and stale snapshots rather than relying only on a fixed interval.
Should an agent automatically correct every position mismatch?
No. First confirm that the broker snapshot is fresh, execution events are complete, and no working order explains the difference. If state is ambiguous, block risk-increasing orders and investigate rather than sending a speculative repair.
Which metrics matter for broker position reconciliation?
Track signed and absolute quantity drift, notional exposure, snapshot age, event-stream lag, mismatch duration, and reconciliation coverage. Measure repair outcomes and high-percentile resolution time as well as averages.