In an algorithmic trading system, no person reviews an order before it goes out: if the strategy gets it wrong, the error reaches the broker. That is why every system needs a risk control of its own, between the strategy and the order, that approves, reduces or rejects it. Interactive Brokers checks every order against what it knows (the account’s funds and margin, the price’s distance from the market and the configured precautions), but it doesn’t know each strategy’s limits, positions or signals.
Three errors that don’t come from the strategy
Many dangerous orders don’t come from the strategy; they come from the system around it: a restart, a data point, a contract’s name. In 2012, after an update, a US broker-dealer’s order-routing system sent millions of orders by mistake over 45 minutes, and the firm lost more than USD 460 million, according to SEC staff. Three lessons that hold for any system, learned while building Console:
- Measure the age of the decision, not of the order. After a restart, a system can rebuild orders from old decisions. Athena saw it in Console: newly created orders carrying decisions from strategies stopped an hour earlier. The file was seconds old; only the decision’s time showed the problem. The age that matters is the signal’s, measured just before sending.
- A dollar limit can’t catch a wrong price. If the price is wrong, the quantity and the amount are computed with that same price, and the limit is satisfied. In Console, a price near zero passed the «above zero» filter and produced an absurd quantity that no dollar limit stopped. It takes a minimum plausible price and a quantity ceiling per instrument, independent of the price. In Console, that floor and an absolute quantity ceiling act when the order is sized, before the 11 checks.
- Identify every price by its contract, not by its name. At Interactive Brokers, different contracts can share a label: two currency pairs both appear as «USD». The same happens with futures: every expiry of the E-mini S&P 500 shares the symbol «ES». If prices are keyed to the name, one contract is valued at another’s price. It happened to Athena: its loss monitor saw a loss that didn’t exist and stopped everything. The contract identifier (conId) is the only safe key.
None of these errors is a strategy’s. That is why the control trusts nothing it receives: every order passes through it before it is sent, and it can approve, reduce or reject it.
What Interactive Brokers checks, and what it doesn’t
- Funds and margin. On every order, Interactive Brokers checks the account’s equity and margin, and rejects the order if they fall short.
- Price. It can reject a limit order priced too far from the market.
- Order precautions. Trader Workstation’s order presets set a size limit, a total value limit and a maximum price distance from the market. On an order entered by hand they show a warning, and the order can still be sent; an order sent through the API that exceeds them can be held or rejected.
- The API setting. Under Global Configuration › API › Precautions, «Bypass Order Precautions for API orders» lets API orders that exceed those limits through without a warning. Interactive Brokers’ guide for third-party software explains how to switch it on; once it is on, that line of checks is gone.
- Pre-Trade Compliance. A tool for advisors, brokers, investment managers, proprietary trading groups and organisations to apply trading restrictions to accounts and users. It is not designed for an individual account running its own strategies.
All of this works as a second line. Athena keeps the order precautions on in its own operation, behind its own control. But none of these checks knows which strategy sent the order, how much of the position belongs to it or whether its signal is fresh: only the system that runs it knows that.
If they stay on, set them above the system’s own limits: that way they stop an absurd order that slips through without refusing a normal one, a close included.
Which checks to run before every order, and in what order
Order matters, and it follows a logic. First, what stops all new risk: the emergency switch and reduce-only mode. Then, whether the order is valid: a fresh signal, an allowed instrument, a current price and books reconciled with the broker. Last, the limits, starting with the day’s loss; those that can reduce the order come at the end, so each one measures the size the previous one left. Once a check rejects the order, the rest are not evaluated. This is Console’s sequence:
| Check | What it prevents |
|---|---|
| Emergency switch (kill switch) | Any new risk while an operator has stopped trading |
| Reduce-only | New positions while only exits are allowed |
| Signal age | Acting on a signal that arrived late, for example after a reconnection |
| Allowed instrument | An order for a contract outside the approved list |
| Fresh price | Sizing an order on a price that stopped updating |
| Books reconciled with the broker | Adding risk while recorded positions and the broker’s disagree |
| Daily loss | Continuing to add risk after the day’s loss limit |
| Per-instrument limit | Concentration in a single stock, future or currency, measured in units and in dollars |
| Order size | An order far larger than intended |
| Gross exposure | Total exposure above the planned level |
| Leverage | Borrowing above the planned level |
In futures, exposure is measured by the contract’s notional value (the price times the multiplier), which can far exceed the margin posted.
Approve, reduce or reject
Not every breach calls for the same answer. An order that would push one stock past its limit can be reduced to the size that fits; an order for an instrument that isn’t allowed is rejected. Either way, the decision and its reason are recorded, so it is always possible to answer why a strategy traded, or didn’t.
A control that never acts hasn’t been tested
A control that never rejects anything looks the same as one with nothing to stop. That is why each control is tested by provoking the case it must stop, and also the one it must let through: in Console, each of the 11 controls has automated tests for both.
Limits must not trap a close
A system that blocks new risk can also block the exit. Risk limits (daily loss, exposure, leverage) shouldn’t stop an order that only reduces the position; validity checks (contract, size, signal age) still apply. And «reducing» is best measured on the account, counting working orders, not only on the strategy’s book: if 40 shares remain and a sale of 30 is already working, another sale can only be for 10; and if closing one strategy’s book increases the account’s position, that order no longer reduces and goes through the limits. While building Console, Athena learned it when dismantling 30 strategies at once: a guard against orders from stopped strategies was also rejecting their own closes. Since then, in Console closes take their own path, with the contract identified and the size matched to what the broker holds.
Several strategies in one account: limits for the whole portfolio
Interactive Brokers keeps a single net position per contract for the whole account, even when several strategies trade it. That is why each strategy needs its own book, and the control has to see the whole portfolio: gross exposure and leverage are totals across strategies. Closes too: in Console, a strategy correctly closing its own book left the account short, because it used shares that belonged to others. Since then, every close is capped at what the account holds, net of what belongs to the others. When one strategy buys what another sells, the two orders are crossed internally and only the difference, if any, reaches the broker. And the books are compared with the broker often: in Console, positions every two minutes, executions every ten and the day’s result, to the cent, every night.
In currencies, moreover, the position Interactive Brokers reports is a sum of trades, not each currency’s balance: Athena measured it in Console, with a position of zero while the account held 25,000 pounds. That is why currency books are best compared with each currency’s balance.
What each platform brings for several strategies in one account is compared in the deployment guide.
Athena QS Console
Athena QS Console runs several Python strategies in one Interactive Brokers account as one portfolio: a book per strategy and, before every order, 11 checks in order, including the whole portfolio’s daily loss, gross exposure and leverage, with each decision logged with its reason. Athena uses it with real capital. The user installs and operates the software.
Explore Athena QS Console →Questions and answers
Does Interactive Brokers check orders sent from Python?
Yes, against what it knows: the account’s funds and margin, the price’s distance from the market and the precautions set in Trader Workstation, which can hold or reject an API order unless the option to bypass them is on. It doesn’t know each strategy’s limits, positions or signals: only the system that runs the strategy checks those.
Where should the control run?
Between the strategy’s decision and the call that sends the order, so that every path that sends, amends or retries an order passes through it. What is entered outside the system, by hand or from another application, doesn’t pass through it: reconciliation catches it.
Does a pre-trade control guarantee a maximum loss?
No. It controls what is sent. Price gaps, partial fills and outages can still produce a loss beyond the intended limit.
Sources
- Interactive Brokers: TWS API settings, Order Precautions
- Interactive Brokers: considerations for automated trading (orders too far from the market)
- Interactive Brokers: third-party software and order precautions
- Interactive Brokers Campus: Configuring TWS presets
- Interactive Brokers: Using the Pre-Trade Compliance tool
- SEC staff: Algorithmic Trading in U.S. Capital Markets (2020), section IV.D
Newsletter
Stay up to date with Athena's publications and market insights.
Athena Quantitative Strategies is a quantitative investment firm based in Santiago, Chile: it manages portfolios, publishes its market analysis and offers the software it uses to trade and research. Athena Quantitative Strategies is not registered in the CMF's Register of Portfolio Managers and is not supervised by it. This content is educational and informational; it is not investment advice, a recommendation or an offer of securities. All investing involves risk, including loss of capital.
