Agentic Trading Index

Broker sandboxes: build tests that expose execution gaps

Developer reviewing a trading dashboard while testing broker sandboxes
Photo by Joshua Mayo on Pexels

At the end of a bad week, a developer stares at a dashboard: the sandbox shows 100% accepted orders, but the live account has duplicate submissions, partial fills and a position that does not match the agent's ledger. The sandbox did not necessarily misbehave. It may simply have tested whether requests were valid, not whether the whole execution path would survive real market conditions.

That gap is why broker sandboxes can appear to lie. Their responses are real within the simulator, but the conditions underneath are often simplified.

A successful test order is evidence that a request passed one path. It is not evidence that a live order will fill at the displayed price, arrive once, or reconcile cleanly after a timeout.

Know what the sandbox is actually simulating

Start by writing down what each response proves. An HTTP 200 may establish that authentication and request parsing worked.

An order status of accepted may establish that basic validation passed. Neither confirms that the broker routed an order to an exchange, found a counterparty or reserved buying power in the same way as production.

Sandbox implementations commonly use synthetic balances, simplified matching and delayed or sampled market data. Some simulate fills from a quote touch. Others fill marketable orders against a reference price, without modelling queue position or available depth. The details vary by product and asset class, so treat documentation as a description of intended behaviour, then verify it with controlled tests.

Map the path from the agent to the broker and back. Include authentication, order validation, acknowledgement, execution reports, cancellation, account positions and recovery after a lost connection.

For each step, record the event that the agent observes and the state it updates. If an order is accepted but no execution report arrives, the agent must not quietly assume either a fill or a failure.

Make the distinction explicit in logs. Keep the request identifier, broker order identifier, client-generated idempotency key, timestamps and each status transition.

Use UTC timestamps with millisecond precision where available. A sandbox that omits an identifier, or returns an order status without a clear timestamp, is telling you something about its limits.

Build a benchmark around observable gaps

Use a fixed set of instruments, order sizes and market conditions. Run the same scenarios in the sandbox and, where permitted, in a tightly limited live account.

These figures are typical planning ranges for common API designs, not audited measurements for any named broker. They are prompts for testing, not service-level guarantees.

BehaviourSandbox typical rangeLive-market typical rangeWhat to test
Order acknowledgement latency50-1,000 ms20-500 msRecord median and 95th percentile, not just the fastest response.
Market-data age at decision100-2,000 ms10-500 msMeasure quote age and reject decisions past the agent's freshness limit.
Market-order completionImmediate to 1 second, often simulated10 ms to several seconds, with partial fills possibleCheck filled quantity, average price and remaining quantity.
Limit-order fill on a price touchOften filled on touchMay not fill at all, depending on queue and available sizeTest touch without fill, partial fill and cancellation after a touch.
Recovery after a request timeoutOften deterministic on retryUnknown until queried; duplicate risk if resubmittedDisconnect after submit, then reconcile before any retry.

Do not compare latency from a single run. Send at least 100 requests across different times, then report median, 95th and 99th percentile.

Separate client-side network time from the broker's acknowledgement time if the API exposes enough timestamps. If it does not, record that uncertainty rather than labelling the whole interval broker latency.

For fill tests, compare requested quantity with cumulative filled quantity, not the order's top-level status alone. Check whether an execution report can arrive before the status endpoint updates. Also test whether cancellation races with a fill: a cancel acknowledgement does not always mean zero shares traded before cancellation took effect.

Exercise failure paths, not just happy paths

Write scenarios that force the agent to make a safe decision with incomplete information. A sandbox suite should include at least these cases:

  • Submit an order and drop the connection before the acknowledgement. Reconnect and query by client order identifier before deciding whether to submit again.
  • Receive an acknowledgement, then delay or omit the execution report. Confirm that the agent waits, polls or escalates instead of marking the order filled.
  • Partially fill a limit order, cancel the remainder and verify that the position reflects only the executed quantity.
  • Send a duplicate request with the same idempotency key, then with a new key. Confirm which behaviour the API guarantees and how the agent detects duplicates.
  • Change the quote between decision and submission. Check that limit prices, price collars and maximum slippage rules still hold.
  • Trigger rate limits, expired credentials, rejected symbols and insufficient buying power. Check that the agent classifies each response and applies a bounded retry policy.

For a disconnect test, kill the process after the request leaves the client but before the response is written to local storage. On restart, reconcile open orders and executions against the broker before placing anything new.

This is the awkward state that creates duplicate exposure. A retry loop with exponential backoff does not solve it unless the order's identity and status are known.

Rate limits need their own tests. If the published limit is, for example, 10 requests per second, test below that rate, at the limit and above it.

Verify whether rejected requests count towards the limit, whether a retry-after value is returned, and whether order submission shares a quota with account queries. Keep retry budgets finite, such as three attempts for a transient read, and do not automatically retry an order submission whose outcome is unknown.

Set pass conditions before comparing results

Choose thresholds that match the strategy's holding period and risk limits. A market-making agent with decisions measured in tens of milliseconds cannot use the same freshness threshold as a daily portfolio rebalancer.

For a liquid intraday strategy, a team might test a quote-age ceiling of 250 ms and alert on 95th-percentile acknowledgement latency above 500 ms. Those are example controls, not universal thresholds.

Define a pass as a property of the whole order lifecycle, not a high acceptance rate. Useful conditions include:

  • Every submitted order can be reconciled to one broker order or an explicit rejection.
  • After a restart, local positions and open orders match broker state before new risk is added.
  • Unknown submission outcomes do not cause blind resubmission.
  • Execution quantity and average price reconcile with fills, including partial fills and fees where provided.
  • Stale data, rate limits and rejected orders lead to a bounded response, not an unobserved loop.

Track discrepancies by category. For each scenario, save the request, response, event stream, broker state and expected agent state. Report counts as well as percentages. If 2 of 20 cancel tests leave a stale local order, "90% passed" hides a failure that can compound. Repeat tests after API version changes and after changes to the agent's order-management code.

Keep sandbox results separate from production evidence. A sandbox is useful for contract tests, schema validation, state-machine tests and testing recovery logic without risking capital.

It is weak evidence for queue priority, market impact, exchange routing or live slippage. A small live pilot can test some of those behaviours, but it brings real financial risk and needs strict size limits, kill switches and monitoring.

For teams that need an additional controlled environment to exercise agent workflows, agentic paper trading from $9.99 a month is one option to assess. Treat any paper environment as a test harness, not as proof of a broker's production execution. Keep the benchmark portable so that results from one simulator do not become assumptions about another.

Promote only the behaviours you have verified

Before enabling unattended orders, set a maximum position, maximum order value, daily loss limit and permitted instrument list. Set a hard cap on open orders and define what happens when the broker's account state cannot be queried.

For an early pilot, a typical control might limit each order to 0.1-1% of account equity and stop trading after a small, pre-agreed daily loss. The right numbers depend on strategy risk and capital; the point is to make limits enforceable outside the strategy logic.

Use a staged release. First run the agent in shadow mode, producing intended orders without submission.

Then allow a small number of live orders with a human reviewing alerts and fills. Only move to unattended operation after reconciliation, duplicate handling, cancellation and kill-switch tests have passed repeatedly. Keep an independent process able to cancel open orders and disable new submissions if the trading process becomes unhealthy.

Alert on state disagreement, not only on process failure. A healthy service can still hold a wrong position.

Useful alerts include an order without a terminal state after a set interval, broker and local quantities that differ, stale market data, repeated rejects, and a sharp rise in acknowledgement latency. Make alerts actionable: include the instrument, order identifier, last known status and the safe action the operator can take.

This advice does not apply unchanged to a strategy that only submits infrequent, human-reviewed orders and never manages exposure unattended. In that case, sandbox tests still help catch malformed requests, but the live operator can inspect each order and resolve uncertainty before it compounds.

Frequently Asked Questions

What does a broker sandbox actually test?

It usually tests authentication, request formatting and some order-state behaviour. Fill simulation, liquidity, queue position and recovery after ambiguous timeouts may be simplified or absent. Check each behaviour rather than treating a successful request as evidence of live execution.

Can a sandbox predict live order fills?

Not reliably unless its matching model represents live liquidity, order priority and partial fills. Many sandboxes fill on a quote touch or use a reference price. Use them to test order logic, then verify execution assumptions with appropriately limited live testing.

How should an agent handle an order submission timeout?

Do not submit the order again blindly. Query the broker using the original client order identifier or idempotency key, reconcile open orders and executions, then retry only when the original outcome is known and the API's rules permit it.