At a glance
- What matters most
- Reliability and error semantics, not feature count
- Critical feature
- Client-supplied order IDs for idempotent retries
- Commonly overlooked
- Reconnection behaviour and rate limit handling
- Test before building
- The sandbox, and then live at minimum size
Key takeaways
- Client-supplied order IDs are the single most important API feature, because they make retries safe after a timeout.
- Rate limits and reconnection behaviour determine how your system fails, which matters more than how it performs normally.
- Sandbox environments frequently behave differently from production, so verify critical paths with real orders at minimum size.
- Order type support varies more than expected: bracket orders, trailing stops, and good-till-cancelled semantics differ between brokers.
- Read the documentation on partial fills, rejections, and order state transitions before writing code, because those paths are where bugs cause losses.
Evaluating an API
| Property | Why it matters | How to check |
|---|---|---|
| Client order IDs | Makes retries idempotent after timeouts | Documentation; test a duplicate submission |
| Order type coverage | Determines what strategies are implementable | List the types your strategy needs and verify each |
| Rate limits | Determines how many instruments you can monitor | Documentation, then test the limit deliberately |
| Streaming versus polling | Affects latency and data volume | Check whether fills stream or must be polled |
| Reconnection semantics | What happens after a dropped connection | Disconnect deliberately and observe recovery |
| Order state model | How states transition and what is reported | Read carefully; ambiguity here causes state bugs |
| Sandbox fidelity | Whether testing reflects production | Compare a sandbox order against a live minimum-size order |
| Historical data access | Whether you can backtest on the same source | Check depth, granularity, and adjustment |
| Multi-account and sub-account support | Separating strategies cleanly | Documentation |
REST, WebSocket, and FIX
| Protocol | Typical use | Strengths | Weaknesses |
|---|---|---|---|
| REST | Order placement, account queries | Simple, well documented, easy to debug | Request-response latency; polling for updates |
| WebSocket | Market data, fill notifications | Push updates, lower latency | Reconnection handling is your responsibility |
| FIX | Institutional order routing | Industry standard, rich semantics | Complex; usually unavailable to retail |
| Broker SDK | Wrapper over the above | Faster to start | Hides behaviour you may need to control |
A common architecture uses REST for order submission, where confirmation matters more than latency, and WebSocket for market data and fill notifications, where timeliness matters. The critical detail is that WebSocket connections drop routinely, and your reconnection logic must resynchronise state rather than assuming continuity.
Failure modes to design for
- 1
Request timeout on order submission
Query by client order ID before retrying. Never retry blindly; that is how duplicate positions are created.
- 2
Rate limit exceeded
Implement exponential backoff with jitter, and track your request budget proactively rather than reacting to rejections.
- 3
WebSocket disconnection
On reconnect, do not assume you know the state. Query positions and open orders and reconcile before acting.
- 4
Partial fill notification
Update state from actual filled quantity. Every downstream calculation must use the real position, not the intended one.
- 5
Order rejection
Parse the reason. Insufficient margin, invalid price, and halted instrument each require a different response, and none should be a blind retry.
- 6
Stale or missing market data
Track the timestamp of the last update and refuse to trade on data older than a threshold. Fail closed.
- 7
Authentication expiry
Tokens expire, often at inconvenient times. Refresh proactively rather than on the first failed request.
Credentials and security
- Never commit credentials to source control. Use environment variables or a secrets manager, and add credential files to your ignore list before the first commit.
- Use read-only keys where possible. Many APIs allow keys scoped to data access only, which is appropriate for research processes.
- Restrict withdrawal permissions. Trading keys should never have withdrawal rights, particularly on crypto venues.
- Whitelist IP addresses where the broker supports it, so a leaked key cannot be used from elsewhere.
- Rotate keys periodically and immediately if a machine is compromised or a developer leaves.
- Log requests without logging credentials. It is easy to accidentally write an authorisation header into a debug log.
- Separate research and execution credentials, so a bug in a research script cannot place orders.
Pre-build checklist
- Does the API support client-supplied order IDs?
- Are all the order types your strategy needs available and tested?
- What are the rate limits, and can you monitor your intended universe within them?
- How are fills reported, and is there a way to reconcile positions authoritatively?
- What happens to open orders if your connection drops or your process restarts?
- Does the sandbox reflect production behaviour for the paths you depend on?
- Are there documented maintenance windows, and how does your system behave during them?
- Can you scope credentials to trading only, without withdrawal rights?
- Is historical data available from the same source you will trade on?
- What is the documented and observed reliability, including during high-volatility sessions?
Frequently asked questions
What is the most important feature in a trading API?
Client-supplied order IDs, which make retries safe after a timeout. Without them, an ambiguous submission leaves you unable to determine whether an order exists, and both retrying and not retrying carry real risk. Every other feature is secondary to this one.
Should I use REST or WebSocket?
Both, for different purposes. REST for order submission, where explicit confirmation matters more than latency, and WebSocket for market data and fill notifications, where timeliness matters. The essential work is in the reconnection logic, which must resynchronise state rather than assume the connection was continuous.
Are broker sandboxes reliable for testing?
Partially. They verify request formats and basic flows but frequently differ from production in fill behaviour, latency, rate limiting, and error responses. Test in the sandbox first, then validate every critical path with real orders at minimum size before relying on the system.
How do I handle API rate limits?
Track your request budget proactively rather than reacting to rejections, batch requests where the API supports it, cache data that does not change frequently, and implement exponential backoff with jitter for the cases you cannot avoid. Design your universe size around the limit rather than discovering it in production.
What happens to my orders if my system crashes?
It depends on the broker and the order type. Resting orders generally remain active, which is why protective stops should be submitted to the broker rather than managed in your code. On restart, query the broker for positions and open orders and reconcile before taking any action.
Test this idea before you trade it
Describe the rules in plain language and AlgoTrader AI turns them into a structured strategy blueprint with a configurable historical backtest, cost assumptions, and exportable code.
Build a backtestKeep reading
- Algo & QuantHow to Build a Trading Bot: A Practical Walkthrough
- Algo & QuantAlgorithmic Trading Guide: From Idea to Running System
- FoundationsHow to Choose a Broker: Costs, Execution, and Safety
- MechanicsOrder Types Explained: Choosing How You Enter and Exit
- Algo & QuantExecution Algorithms: TWAP, VWAP, and Getting Filled Well
- Algo & QuantMarket Data Guide: Types, Sources, and What You Actually Need
Referenced by
Educational use only. This guide explains how a strategy works. It is not investment advice, not a recommendation, and no result described here is a forecast. Test any approach on historical and out-of-sample data, size positions conservatively, and never risk money you cannot afford to lose.