In week one, establish whether the broker API can place, amend and reconcile a small set of orders under controlled conditions. By week six, the question is whether the agent can keep its account state correct through disconnects, partial fills, rejected orders and market-session changes, without a person stepping in. A successful test request proves very little about unattended operation.
Run the checks below against the actual API version and account type intended for deployment. Record request and response payloads with credentials and personal data removed. Treat each broker's documentation as a starting point, then verify the behaviour you depend on.
Define the contract before connecting the strategy
Write down what the agent expects from the broker and what the broker promises in return. Specify supported asset classes, order types, time-in-force values, trading sessions, account currencies, fractional quantities and short-selling rules. Record minimum quantity, quantity step and price increment for each instrument. A quantity accepted in a sandbox may still fail against the live instrument's lot rules.
Separate the order lifecycle into states your software can represent: submitted, acknowledged, working, partially filled, filled, cancel pending, cancelled, rejected and expired. Map the broker's status names to these states.
Do not treat an HTTP success response as proof that an order is working. Some APIs accept a request before returning an order identifier; others return a rejection in a successful HTTP response.
Agree on the source of truth for open orders, fills, positions, cash and buying power. The agent's local ledger is useful for decisions, but it must be reconciled against broker records. Define what happens when those sources disagree, including whether the agent pauses new entries, cancels working orders or raises an alert.
Keep a written inventory of required endpoints and permissions. A strategy that only needs to trade should not have account-transfer permissions.
Check token expiry, refresh behaviour, key rotation and whether the broker supports separate credentials for paper and live accounts. Store secrets outside source code and logs.
Run the week-one broker API checklist
Use a small, repeatable test script before building the strategy around assumptions. Save timestamps, request identifiers and returned state for each test. Run this checklist in the sandbox first, then repeat the relevant cases with the smallest permitted live order if the account and rules allow it.
- Check authentication. Confirm how the token expires, how it is refreshed, and what a permission failure looks like. Verify that a read-only key cannot submit orders.
- Read the limits. Find documented limits by endpoint and account. Send requests below the limit, then handle a 429 response and any retry-after header. Do not assume the limit applies uniformly to market data and trading calls.
- Submit each required order type. Test market, limit and stop orders only if the strategy needs them. Check accepted fields, time-in-force, price precision, quantity precision and rejection messages.
- Test amend and cancel. Record the state transitions and response times. A cancel request can be pending while a fill arrives, so confirm the final order and fill records before releasing reserved risk.
- Cause an ambiguous timeout. Interrupt the client after sending a request but before receiving the response. Query by client order ID or list recent orders before retrying. Confirm whether the broker enforces uniqueness or merely stores the ID.
- Reconcile a partial fill. Compare executions, remaining quantity, average fill price and position. Check whether one order produces several fill events and whether corrections or trade busts can arrive later.
- Restart from stored state. Stop the process with working orders, restart it, then rebuild its view from broker orders, executions and positions. Confirm that the agent neither duplicates an order nor forgets exposure.
For a repeatable test harness, Agentic Trading Index offers agentic paper trading from $9.99 a month through its paper-trading platform. Use it to exercise the agent's own state handling, but still validate broker-specific behaviours against the broker interface.
Prove order handling under failure
Order placement is a distributed operation. The client can send a request, the broker can accept it, and the response can disappear before reaching the client. A blind retry may create a second live order. Give every intent a durable client order ID generated before submission, and persist the intent before making the network call.
On timeout, mark the intent as unknown, not failed. Query by client order ID if supported.
Otherwise fetch recent orders and match on account, instrument, side, quantity, price and submission window. Only submit again when the first request is known not to have created an order. If the API does not make this safe, use a conservative pause and manual escalation path.
A timeout is uncertainty about the request, not evidence that the broker rejected it.
Test partial fills against your position and risk calculations. If a 100-share order fills 35 shares, the agent has 35 shares of exposure while 65 remain working. On a cancel request, keep the unfilled quantity reserved until the broker confirms cancellation or the order fills. A late execution can arrive after a cancel response, so reconcile executions as well as order status.
Streaming updates reduce detection delay, but streams can drop events or disconnect. Track sequence numbers or event identifiers where available. On a gap or reconnect, fetch a fresh snapshot of open orders, executions and positions before trusting the stream again. If the broker offers no sequence mechanism, compare periodic snapshots and make the recovery rule explicit.
Log the strategy decision, client order ID, broker order ID, request time, acknowledgement time, each state transition and final execution. Use a monotonic clock for measuring durations and retain UTC timestamps for cross-system comparison. Redact credentials and avoid logging full account details. These records make it possible to distinguish a strategy error from a transport or broker-state problem.
Measure latency, limits and account truth
Measure timings from your deployment location, at the times your agent will trade. Separate client-to-broker round-trip time from order acknowledgement and fill time. The first two are API behaviour; the fill also depends on liquidity, order type and market conditions. Use percentiles, not just averages, and record the sample size and market session.
The figures below are typical market ranges for planning tests, not guarantees for a particular broker. Limits and timings vary by API, account, network route and venue. Replace them with measured values for the exact endpoints and environment under consideration.
| Measure | Typical range | What to test | Operational response |
|---|---|---|---|
| REST request round trip | 50-500 ms | Median and 95th percentile during intended sessions | Set request deadlines and avoid treating a slow response as a rejection |
| Order acknowledgement | 50-500 ms | Time from send to confirmed broker order ID | Keep the intent unresolved until queried after timeout |
| Streaming update delay | 10-250 ms | Event delay, disconnects and recovery after a sequence gap | Resynchronise from broker snapshots before acting on stale state |
| API request allowance | 5-60 requests per second | Endpoint-specific limits, bursts and 429 behaviour | Use a token bucket, backoff and priority for cancels and risk checks |
| Cancel confirmation | 50-1,000 ms | Cancel-pending duration and fills racing with cancellation | Keep exposure reserved until final order and execution state agree |
Rate-limit handling needs more than exponential backoff. Use a token bucket or equivalent client-side limiter, honour retry-after when supplied, and add jitter so several processes do not retry together. Give risk-reducing actions, such as cancelling an exposed order, priority over routine polling. Set a maximum retry window; after it expires, pause new entries rather than building an unbounded queue.
Reconcile positions and cash on a schedule that matches the strategy's holding period, and after reconnects, restarts or execution events. Compare signed quantity, average cost, realised profit and loss, cash and buying power. Check which values are delayed or adjusted for unsettled trades. A position endpoint may update before a portfolio summary, so document tolerances and the order in which the agent trusts fields.
Gate live operation on evidence
Week one should produce a small evidence pack: endpoint inventory, permission map, order-state mapping, saved test cases, latency measurements and known failure modes. Week six should not mean simply switching a configuration flag. Use the intervening period to run the agent against delayed or paper data, exercise restarts, and review its decisions and reconciliation output across different sessions.
Set explicit live gates. For example, require zero unexplained position mismatches during a defined test window, successful recovery from a dropped stream, and no duplicate orders in timeout tests. Choose thresholds that match the strategy and account. A low-frequency strategy may tolerate a longer polling interval than an intraday strategy, but neither should silently trade from stale account state.
Start with permissions limited to the necessary instruments and order types. Set broker-side buying-power or loss limits where available, alongside local limits for order value, total exposure, daily loss and maximum open orders. Local checks can fail with the process; broker-side controls can be broader or slower to update. Use both where possible, and test what happens when either rejects an order.
Before unattended operation, define who or what stops the agent. A kill switch should stop new submissions and cancel eligible working orders, then verify the resulting state. Decide how the service behaves if the broker API, market data or risk calculation becomes unavailable. For many strategies, the safe response is to stop adding risk, preserve enough connectivity to manage existing orders, and alert an operator.
Keep a deployment runbook with the account identifier, session calendar, start-up reconciliation steps, monitoring thresholds and rollback procedure. Review it when the broker changes API versions, rate limits or order semantics. If the broker cannot provide reliable identifiers, recoverable state and usable execution records, record that as a platform limitation rather than hiding it in agent logic.
If this were my operation, I would first build a small order-state harness that persists client order IDs and reconciles every intent against broker orders, executions and positions. I would run the timeout, partial-fill and restart tests before connecting any strategy that can add risk.
Frequently Asked Questions
What should I test first in a broker API?
Test authentication, order submission, acknowledgement, cancellation and reconciliation of fills and positions. Then simulate a timeout after sending an order and verify that the client checks for an existing order before retrying.
How should an agent handle a broker API timeout?
Treat the request as unresolved, not rejected. Query by client order ID or inspect recent orders and executions before deciding whether to retry, and pause new risk if the outcome cannot be established.
How often should a trading agent reconcile broker positions?
Reconcile after reconnects, restarts and execution events, as well as on a schedule appropriate to the strategy's holding period. Intraday systems usually need tighter checks than low-frequency systems, especially around working orders and partial fills.
Can a broker sandbox prove an API is safe for live trading?
No. A sandbox can test request formats and some state transitions, but it may not reproduce live latency, liquidity, rejection patterns or rate limits. Verify broker-specific behaviour with the smallest permitted live activity and retain conservative risk controls.