Broker apis
Order Types, Partial Fills, and Idempotency: Making Every Order Safe to Retry
On November 23, 2026, four major brokerages were reported down at once. Your order timed out — did it land? A naive retry doubles your position; an idempotent retry doesn't. The difference is one ID, chosen before the first submit.
Educational content, not investment advice. Trading involves risk of loss.
In brief
- On November 23-24, 2026, Schwab outage reports peaked at 3,423 an hour and users reported downtime across Robinhood, E*TRADE, Fidelity and Schwab at once. The expensive part of an outage is the retry: a timeout is not a rejection, and guessing wrong doubles the position.
- In this article's executed simulation, a naive retry with a fresh ID created 2 orders totalling 200 shares against an intended 100 (2.0x); the same timeout retried with the same client order ID was rejected as a duplicate, leaving exactly 100 shares (1.0x).
- Alpaca rejects a duplicate client_order_id; Binance accepts a repeated newClientOrderId only after the previous order fills; Interactive Brokers requires a unique, monotonically increasing order ID from nextValidId. Derive the ID from strategy state, never a fresh UUID per attempt.
- Partial fills are the normal case: a 100-share order had filled 40 when the connection dropped, and resubmitting the full 100 would have left 140 shares (1.4x). Query the broker by client ID after any drop and cancel or replace only the remainder.
On this page
The short answer
On November 23, 2026, outage reports for Charles Schwab peaked at 3,423 an hour and stayed high for two hours; Robinhood's reports stayed elevated for five. The next day, users reported downtime across Robinhood, E*TRADE, Fidelity and Schwab at once, as U.S. stocks surged and Nvidia rose more than 30%. For a systematic trader, the outage itself is not the expensive part. The expensive part is the retry: your order submission timed out, you do not know whether it landed, and if you guess wrong you hold twice the position you intended. Three things decide whether a retry is safe: the order type, which decides what "filled" means; a client order ID, which makes the retry idempotent; and reconciliation, which tells you what you actually hold before you act again. In the simulation below, a naive retry produced twice the intended position; an idempotent retry produced exactly the intended one.
What each order type actually promises
Order types are not flavors of the same request. Each one is a different contract with the market, and the differences show up exactly when conditions are worst.
A market order is a request to buy or sell at the currently available price. It provides the most likely method of filling, and it fills nearly instantaneously — but the fill price may slip with available liquidity, and a short-term price spike can fill you at a price you never intended.
A limit order buys or sells at a specified price or better. The price protection is real, but a limit order may not be filled for a long time, if at all — and it usually fills in pieces, not all at once. A limit order is not "filled or not." It is filled in quantities that move, and your code has to treat filled_qty as a number, not a boolean.
A stop order buys or sells when the price moves past a point, then becomes a market order once elected. It does not guarantee the fill price after conversion. A stop-limit order becomes a limit order instead of a market order when the stop is reached — and if the market gaps through the stop without trading at your limit, the order stays active as a limit order until it is executable or cancelled. That is the safer exit in a fast market and the slower one in a gap.
Time-in-force finishes the contract: DAY dies at the close, GTC rests until filled or cancelled, IOC (immediate-or-cancel) takes whatever is available now and cancels the rest, FOK (fill-or-kill) demands the whole quantity or nothing. A bracket order chains the entry to a take-profit and a stop-loss — and if the take-profit partially fills, the stop-loss is adjusted to the remaining quantity, so the exit always matches what you actually hold.
The timeout that doubles your position
A timeout is not a rejection. The request reached the broker, the broker accepted it, and the response was lost on the way back. On a normal day that is a rare race; on a day like November 23–24, 2026, when four major brokerages were reported down at once, it is the routine case. The strategy that treats "no response" as "no order" will resubmit — and now holds two orders for one signal.
Measured, with a broker that rejects duplicate client order IDs the way Alpaca does: a naive retry with a fresh ID created 2 orders totalling 200 shares against an intended 100 — a 2.0x position. The same timeout retried with the same client order ID was rejected as a duplicate, leaving 1 order and 100 shares — exactly 1.0x intended. The difference between the two outcomes is one string, chosen before the first submit.
Idempotency keys, broker by broker
Every major broker gives you the same primitive under a different name: a client-supplied identifier that makes a resubmission safe. The semantics differ, and the difference matters.
Alpaca: client_order_id. Each order carries a unique client-provided ID; if you do not provide one, the system generates one. Submit the same ID twice and the second submission is rejected as a duplicate — a 422 — so a retry after a timeout is safe either way: it succeeds, or it is rejected as a duplicate. You can also look the order up by that ID afterwards, which is the reconciliation hook.
Binance: newClientOrderId. It must be unique among open orders. Orders with the same ID can be accepted only when the previous one is filled; otherwise the order is rejected. That is the safe behavior stated plainly: while your first order is still open, the retry is refused; once it is filled, the ID is free again.
Interactive Brokers: the order ID sequence. The TWS API requires every API order to carry a unique integer order ID, starting from the nextValidId announced when you connect, increasing monotonically within the session. A reused ID is a collision, not a safety net — so persist your own sequence and never restart it from nextValidId without your ledger, or a reconnect replays IDs your broker already saw.
The rule across all three: derive the ID from the order's identity — strategy, symbol, signal bar, side — never from a fresh UUID per attempt. A UUID retry is just a new order wearing a disguise, and the broker will happily accept it twice.
Partial fills: reconcile before you act
The second failure mode is subtler than the duplicate. Your order partially filled — 40 of 100 shares — and then the connection dropped. Your local state says "0 filled, order lost." The broker says "40 filled, 60 resting." If you resubmit the full 100 on your local belief, you end up holding 140 shares against an intended 100 — 1.4x. If you ask the broker first, by your client order ID, you learn the truth: 40 filled, 60 remaining. Cancel the remainder and your final position is the 40 shares you actually own, with the order closed.
Three rules follow. Never act on pre-drop memory. Always query the order by your client ID after a reconnect or a timeout, before sending anything new. And treat filled_qty as the truth — cancel or replace only the remainder, never the original quantity. The broker-side behavior already works this way: a bracket's stop-loss adjusts to the remaining quantity after a partial take-profit fill. Your client should do the same.
The pattern, in code
The whole pattern is two functions and one ID. The code below is the exact code run for this article, against an in-memory broker with Alpaca-style duplicate rejection; the numbers quoted above are its output.
class FakeBroker:
"""In-memory broker with Alpaca-style client_order_id semantics."""
def __init__(self):
self.orders = {}
self.next_broker_id = 1
def submit(self, client_order_id, symbol, side, qty, limit_price):
if client_order_id in self.orders:
return ("duplicate_rejected", self.orders[client_order_id])
order = {"broker_id": self.next_broker_id,
"client_order_id": client_order_id,
"symbol": symbol, "side": side, "qty": qty,
"limit_price": limit_price,
"filled_qty": 0, "status": "new"}
self.next_broker_id += 1
self.orders[client_order_id] = order
# The market takes part of the order at once: 40 of 100 fill.
order["filled_qty"] = 40
order["status"] = "partially_filled"
return ("accepted", order)
def get_order(self, client_order_id):
return self.orders.get(client_order_id)
def cancel(self, client_order_id):
order = self.orders.get(client_order_id)
if order and order["status"] in ("new", "partially_filled"):
order["status"] = "canceled"
return True
return False
def submit_idempotent(broker, client_order_id, symbol, side, qty,
limit_price, drop_response=False):
# One ID per intended order, derived from strategy state.
status, order = broker.submit(client_order_id, symbol, side, qty,
limit_price)
if drop_response:
# The order landed; the response was lost on the wire.
raise TimeoutError("no response from broker")
return status, order
def reconcile_and_cancel(broker, client_order_id):
order = broker.get_order(client_order_id)
remaining = order["qty"] - order["filled_qty"]
if remaining > 0:
broker.cancel(client_order_id)
return order["filled_qty"], remaining
Run every order submission through submit_idempotent, and every reconnect through reconcile_and_cancel before the next order goes out. The two functions are the whole difference between a 2.0x position and a 1.0x one, and between a 1.4x surprise and a clean 40-share position.
What to do next
Before your next live session, audit three things in your client: every order carries a deterministic client order ID derived from strategy state, stored before the submit; every retry reuses that same ID instead of minting a new one; and every reconnect queries the broker by client ID and reconciles fills before the next order goes out. If any of the three is missing, your strategy's position is one dropped response away from doubling. Rate limits, downtime, and reconnects covers the pacing and backoff that keep the retry from becoming a second outage, and how to connect Python to your broker's API shows the first-order flow this retry-safety protects; automating a strategy end to end puts the order submission inside the full signal-to-fill loop, and market data APIs covers the feed-health checks that catch the gaps a reconnect misses.
If the order plumbing is the bottleneck — the ID scheme, the retry logic, the reconciliation across brokers — that is the kind of build the engineering desk does. BlackShore Agency is the engineering firm inside Blackshore Technologies, the same parent company as Quantide, and a desk engineer can wire idempotent, reconciling execution across your brokers so a timeout costs you a retry, never a doubled position.
Frequently asked questions
My order submission timed out. Is it safe to just send it again?
No. A timeout means the response was lost, not that the order was rejected — the broker may have accepted it. Retrying with a fresh ID creates a second order. Retry with the same client order ID: Alpaca rejects the duplicate and Binance refuses it while the first is open, so the retry is safe either way.
How does each major broker handle idempotency keys?
Alpaca: client_order_id — a duplicate submission is rejected. Binance: newClientOrderId — unique among open orders, re-accepted only after the previous order fills. Interactive Brokers: a unique integer order ID from the nextValidId sequence, increasing monotonically within the session.
My order partially filled and then the connection dropped. What do I do?
Ask the broker, by your client order ID, before acting. In this article's simulation a 100-share order had filled 40 when the connection dropped; resubmitting the full 100 would have left 140 shares (1.4x). Querying first and cancelling only the remaining 60 left a clean 40-share position.
Which order type should I use for an automated exit?
A market order fills fastest but the price can slip. A limit order buys or sells at your price or better but may fill only partly or not at all. A stop order becomes a market order once elected and does not guarantee the fill price; a stop-limit becomes a limit order, which can stay unfilled in a gap.
Sources
- Placing Orders — Alpaca docs (order types, client-provided unique ID, bracket partial-fill adjustment)
- Trading endpoints — Binance Open Platform (newClientOrderId unique among open orders; accepted only when previous filled)
- Order Functions — Interactive Brokers Traders' Academy (reqIds / next valid order ID)
- Charles Schwab outage on November 23, 2026 — instatus (reports peaked 3,423/hr, lasted 2h)
- Robinhood, E*TRADE, Fidelity and Charles Schwab Reported Downtime as US Stocks Surge — Hokanews, Nov 24, 2026
- Placing Orders via the Trading API — Tektii Docs (Alpaca duplicate client_order_id rejected with 422; Binance returns existing order)
Related reading
- GuideBroker API Rate Limits, Downtime, and Reconnects: The Plumbing That Decides Whether Your Strategy TradesYour strategy trades when the broker's API accepts the request — and every broker rations that. A naive poller lost 44.4% of its requests to 429s; a paced one lost none. The plumbing decides whether your strategy trades.5 min read
- GuideMarket Data APIs for Systematic Traders: Feeds, Latency, and What BreaksOn December 6, 2026, US equities start trading 23 hours a day. Your data feed is about to get a new session, a nightly pause, and a whole new set of ways to silently break. Here is how to pick a market data API and wire it so it fails loudly instead of quietly.6 min read
- GuideHow to Connect Python to Your Broker's API and Place Your First Automated OrderConnecting Python to a broker takes about an hour the first time, and most of it is setup, not code. Here is the full path — Alpaca and Interactive Brokers, paper first — with code that was actually run.5 min read