A broker API is programmatic access to the same account you already trade by hand. Your code sends the order a mouse click would have sent. It subscribes to a stream instead of watching a quote board. It reads positions and balances without a page refresh in the loop. Every serious retail brokerage now exposes some version of this — the Interactive Brokers API (the socket-based TWS API plus a REST-style Client Portal API), the tastytrade API, Tradier's brokerage API, Alpaca's trading API, TradeStation's API — and despite wildly different documentation, they all reduce to the same three surfaces: order routing, market data, account state.
What an API does not provide is an edge. It provides leverage over your own process: journaling that never skips a day, execution that follows written rules instead of a mood. The distance between "I can place an order from Python" and "I run automation I would leave alone with money" is roughly the distance between owning a wrench and rebuilding an engine, and nearly all of it is infrastructure knowledge rather than strategy knowledge.
The three surfaces
Order routing
The order endpoint accepts the same instructions your broker's ticket does — limit, market, stop, stop-limit, and, where the broker supports them, bracket and one-cancels-other structures. You submit, receive an acknowledgment carrying a broker-assigned ID, then receive status transitions: working, partially filled, filled, cancelled, rejected. Two details matter disproportionately. An acknowledgment is not a fill; code that treats "accepted" as "position open" will eventually be wrong at the worst possible moment. And most APIs let you attach a client-assigned order ID to each submission, which lets a retry be recognized as a duplicate rather than filled twice. There is no priority lane: API orders ride the same routing your manual orders do.
Market data
Data is where entitlements bite. Real-time quotes are licensed per exchange, so an API key alone typically yields delayed data until you subscribe to the relevant feeds, at fees that differ for professional and non-professional status. Top-of-book — best bid, best offer, last trade — is the standard tier. Depth of market, the ladder of resting liquidity beyond the inside quote, is a separate and heavier subscription that not every retail API carries for every product. Scale is the other surprise: the consolidated US options quote feed peaks at millions of messages per second, which is why no retail API hands you a raw firehose — you subscribe per symbol and the filtering happens upstream.
Historical endpoints exist nearly everywhere and are the most throttled thing on any broker API. They are built for backfilling a chart in your charting platform, not for bulk research. A project that needs years of futures or options tick data needs a dedicated market-data vendor, and that costs real money.
Account state
Positions, balances, margin requirements, buying power, and fill history live here, and the surface looks so simple that it produces the classic first-project bug: maintaining a local copy of "my position" by summing your own fills and never reconciling it against the broker's number. Fills arrive out of order. A reconnecting websocket silently drops a message. A manual trade from your phone bypasses the bot entirely. Production automation treats broker-reported state as truth and its own ledger as a hypothesis to be re-checked on a timer, forever.
REST versus streaming
REST is request-and-response: ask, receive, disconnect. It is the right shape for the control plane — submitting orders, cancelling them, pulling account snapshots, requesting historical bars. Streaming inverts the relationship: one long-lived connection, usually WebSocket at the retail tier, over which the server pushes quotes and order updates the moment they occur. (FIX connectivity exists at several brokers but is typically an institutional arrangement rather than a retail default.)
The anti-pattern is polling REST for market data. A quote polled once per second is stale for 999 milliseconds of every second and burns your request budget for the privilege. The standard architecture uses REST for actions and streams for facts. Depth feeds add one more discipline: a snapshot followed by sequenced deltas. When your code detects a gap in the sequence numbers, the only correct move is to discard the book and request a fresh snapshot — a ladder built on a missed delta is quietly wrong, which is worse than being visibly down.
Rate limits
Every broker API meters you, and the meters differ by surface: request-per-minute buckets on REST, message caps on order actions, separate and usually harsher pacing on historical data. Exceed them and you receive HTTP 429 responses or, on some socket APIs, a forced disconnect. Four habits absorb nearly all of it:
- Cache what changes slowly — contract specifications, account metadata, instrument lists.
- Batch whatever the API allows to be batched.
- Back off exponentially, with jitter, when told no.
- Honor any retry-after signal the server sends instead of guessing.
Paper endpoints
Most of these APIs ship a simulated environment: Interactive Brokers issues separate paper accounts, Alpaca runs a dedicated paper endpoint, Tradier's sandbox serves delayed data against fictional balances, tastytrade maintains a separate certification environment for testing. Paper is excellent at what it is actually for — proving the plumbing. Does an order round-trip cleanly? Does the reconnect logic actually resync the stream?
What paper cannot validate is the strategy itself, because simulated fills are optimistic: the engine typically fills you the instant price touches your limit, with no queue position, no partial fills, no rejects, no slippage. The arithmetic is unforgiving. Take a deliberately hypothetical contract worth $5 per tick and a system trading 40 round trips a week: one tick of unmodeled friction per side is 40 × 2 × $5 = $400 a week of paper profit that never existed. A strategy whose simulated edge is thinner than its realistic costs is not marginal — it is a losing strategy that has not yet been introduced to itself.
The latency reality
A fair budget for a retail setup: single-digit to low-double-digit milliseconds from your machine to the broker over decent fiber, the broker's own risk checks on top, then the hop to the exchange. Call it tens of milliseconds end to end on a good day. A colocated firm measures the same journey in microseconds, from a server in the same building as the matching engine, over hardware no retail account can rent. You are not one step behind; you are three to five orders of magnitude behind.
That gap decides which projects are dead on arrival. Anything that races — cross-venue arbitrage, or reacting to a print faster than the crowd — loses to participants who paid for the racetrack, and the loss arrives as persistent adverse selection: your fills happen precisely when someone faster wanted out. The gap is irrelevant to everything where seconds do not matter: entries at levels planned before the session, managing an options position against defined exits, systematic journaling, alerts on order flow conditions you would otherwise have to watch for by eye. Retail automation earns its keep by removing human latency — hesitation, revenge — not by competing on network latency.
Founder note: the first automation I ran against a broker API was read-only, and it still paid for itself. It stamped every fill with context I would never have logged by hand. The order-sending version came months later, and it was 90% safety code.
Where first projects go wrong
- Polling for quotes, then blaming the rate limit.
- Trusting a locally computed position instead of reconciling against the broker.
- Writing the happy path for the websocket and nothing for the 2 a.m. disconnect.
- Retrying failed submissions without client order IDs and meeting your first duplicate fill.
- Hardcoding one futures contract symbol and holding the system straight through its expiry roll.
- Assuming your server clock and the exchange's timestamps agree across a daylight-saving change.
- Reading a paper equity curve as evidence about live execution.
- Building entry logic before the kill switch and the daily loss limit.
A sane first project
Start read-only. Pull your fills nightly, join them to the market data around each entry, and let the API build the journal you keep meaning to keep. Read-only code cannot duplicate an order or torch an account, and every integration skill it teaches transfers intact. The second project is semi-automated: code prepares the order and a human clicks confirm. Full automation is the third project — and by then the reconciliation loop, the back-off logic, the kill switch, and the loss cap already exist, which is the correct order to have built them in.