Agentic Trading Index

Position reconciliation for unattended trading agents

Broker trading screens showing positions and order records for position reconciliation
Photo by Yan Krukau on Pexels

What position reconciliation actually compares

At 09:31, one operator sees a missing fill in the agent's log and submits another buy order to restore the expected position. A second operator sees the same gap, pauses new orders and asks the broker for current positions, open orders and executions. The first call can double exposure if the fill arrived late. The second costs time, but starts from evidence held by the party that executed the trade.

Position reconciliation is the routine that compares an agent's view of its exposure with the broker's records, then explains or resolves any difference. It is not just a comparison of share counts. The agent needs to account for working orders, partial fills, cancellations, execution corrections, corporate actions and cash movements that affect the position.

Keep three related records distinct:

  • Target state: what the strategy wants to hold after its latest decision.
  • Expected state: the agent's position after applying known fills and corporate actions.
  • Broker state: the broker's current position and order records.

A target of 100 shares is not evidence that 100 shares have traded. An order accepted by the API is not a fill. The expected state is useful for detecting drift, but the broker state is the operational source of truth for executed exposure.

Normalise identifiers before comparing. A stock symbol, an option contract and a futures contract need stable instrument identifiers, not just display names.

Compare signed quantity and contract multiplier; check average price and currency separately. A quantity match can still hide a large valuation error if the agent has the wrong multiplier or FX conversion.

Make broker state authoritative, not instantaneous

Broker records are authoritative for fills, but they may arrive late or out of order. A streaming execution event can be delayed while a REST position snapshot already reflects it. Conversely, a snapshot may be cached, while a recent partial fill appears only in the execution feed. Treating every difference as a real position error creates unnecessary cancels and replacement orders.

Use the execution ledger to build the expected position, and snapshots to check that ledger against broker state. Store each execution by broker execution ID, with instrument, signed quantity, price, timestamp and any correction or bust reference.

Make processing idempotent: replaying the same event must not add its quantity twice. Keep order status separately, because an order can be partially filled and still working.

For a reliable comparison, record the data's timestamps and sequence information. A useful comparison has a broker snapshot time, the latest execution watermark applied by the agent, and a list of open orders. If the snapshot is newer than the watermark, fetch executions across an overlapping time window, deduplicate by execution ID, then compare again. A small overlap helps catch delayed events; a stable identifier prevents double counting.

Never repair a position from a target alone. First establish what the broker has filled and what it still has working.

Set a short grace period for expected event delay, based on the broker's documented behaviour and your own measured distribution. Typical system designs allow seconds rather than minutes for liquid instruments, but the right threshold depends on feed latency, API limits and trading hours.

During that interval, flag the mismatch as pending and block only actions that could increase the same exposure. A delayed report should not become a duplicate order.

Build a recovery path for partial information

Design reconciliation as a state machine, not a one-off script. The agent should know whether it is in sync, waiting for broker events, investigating a mismatch or operating under a restricted mode. If the broker API times out, the agent cannot infer that an order failed. The request may have reached the broker even if the response did not return.

Use client order IDs that remain stable across retries. After a timeout, query by that ID before submitting another order. If the broker does not support reliable lookup, stop and require a more conservative recovery procedure. Blindly retrying an order is unsafe; blindly assuming success is unsafe too.

A basic recovery sequence is:

  1. Stop new orders that could increase the affected instrument's exposure. Leave unrelated instruments available only if their state is independently verified.
  2. Fetch broker positions, open orders and executions since the last durable watermark. Record retrieval times and raw responses for diagnosis.
  3. Apply unseen executions and corrections idempotently. Resolve timed-out submissions by client order ID, and identify orders that are still working.
  4. Compare normalised quantities and relevant contract details. If the mismatch remains unexplained, keep the instrument restricted and raise an alert for review.
  5. Resume only after the discrepancy is explained, the expected and broker states agree within policy, and any remaining working orders have an explicit owner in the agent logic.

Do not automatically flatten every mismatch. A position could be correct while the agent's event log is incomplete. Flattening would turn a bookkeeping fault into a new market order, with spread, slippage and possible tax or funding consequences. Automatic repair is appropriate only when the cause is known, the order path is idempotent and the repair itself has defined limits.

Test failure cases that occur between request and response: partial fill followed by timeout, cancel acknowledgement arriving after a fill, duplicate execution events, a corrected fill, process restart during a working order, and a reconnect that replays old events. A paper environment is useful for exercising these transitions. Agentic Trading Index paper trading starts at $9.99 a month, and FX-Tech.ai is where to check the service details before choosing a test setup.

Price the controls and set measurable thresholds

Reconciliation has direct infrastructure costs and a less predictable labour cost. A small system may spend tens of pounds or dollars per month on storage, polling and alerts, while the larger recurring expense is often engineering time spent investigating ambiguous broker state. The ranges below are typical market estimates for small to medium automated systems, not audited results for a named company.

They vary with broker fees, account count, request limits, staffing rates and instrument mix. The rows are not additive in every deployment.

Cost or benchmarkTypical rangeUseful operating targetMain cost driver
Snapshot polling, storage and logs$10-$150 per monthPoll every 1-10 seconds where API limits permitAccounts, request quotas, retention and event volume
Alerts and monitoring$0-$100 per monthPage on unexplained exposure drift within 5-30 secondsAlert volume, retention and monitoring coverage
Manual discrepancy review1-8 hours per month, often $50-$200 per hourTrack age and cause for every unresolved mismatchEvent quality, broker tooling and number of strategies
Recovery engineering and testing2-12 hours per month, often $75-$200 per hourReplay every critical failure path before releaseBroker-specific behaviour and deployment frequency

These figures are planning ranges, not a promise that a particular account will incur those costs. A low API bill can still accompany high operational risk if state is wrong for several minutes.

Measure time to detect, time to explain and time to restore a verified state. Also count how often the system enters restricted mode, how many mismatches remain unresolved past their grace period, and how many duplicate or unnecessary orders reconciliation prevents.

Use tolerances that reflect the instrument. For equities, a one-share unexplained difference may matter for a small account and be immaterial for a large one; a universal percentage threshold can conceal small but actionable positions. For derivatives, compare contracts exactly and check multipliers explicitly. For fractional shares or FX, define rounding precision and currency conversion rules. Write the permitted tolerance in quantity and value, and make clear which one takes precedence.

Test disagreement before enabling live orders

A benchmark is only useful if it measures a controlled state transition. Run the same agent through several rounds of broker-event delay, duplicate delivery, API outage and restart. Record how quickly the agent detects each mismatch, whether it blocks the right orders, and whether it returns to service without creating extra exposure.

For each test, capture:

  • Broker snapshot time and latest execution watermark;
  • The agent's expected position before and after recovery;
  • Open order IDs, status changes and any retry decision;
  • Detection time, resolution time and alert destination;
  • Whether a human had to intervene, and why.

Set release criteria before running the tests. For example, require every duplicate execution to be harmless, every timed-out submission to be checked by client order ID, and every unexplained mismatch to block risk-increasing orders within the chosen alert threshold. Choose numeric latency targets from observed broker behaviour, not from a best-case demo. A system that reconciles correctly after one clean replay has not yet proved it can recover from a delayed or contradictory event stream.

Keep the raw broker responses and agent decisions long enough to reconstruct an incident. Store timestamps in UTC, preserve the original payload, and version the normalisation logic.

If a contract mapping changes or a broker corrects a fill, the team should be able to tell whether the mismatch came from execution, transformation or strategy logic. This record also makes it possible to compare brokers and environments using the same test cases.

This week, run one replay test in which a partial fill arrives after the order request times out, and verify that the agent checks broker state before it can submit another order.

Frequently Asked Questions

Which position record should a trading agent trust?

Use broker records as the authority for executed positions and working orders. Maintain an agent-side expected position for comparison, but do not treat a target or an accepted order as proof of a fill.

How often should an agent reconcile positions?

Reconcile on execution events and after reconnects, restarts, order timeouts and material order-state changes. Polling frequency should respect broker API limits; typical designs use snapshots every few seconds where permitted, with event-driven updates between them.

Should an agent automatically close a broker position mismatch?

Not by default. First establish whether the difference comes from a delayed event, a working order, a correction or a real position error. Automatic repair should be limited to understood cases with idempotent order handling and explicit risk limits.