Home › Blog › Algo Trading
Algo Trading

API Trading Risks: Failures, Monitoring and Kill Switches

By Contraday··7 min read

What can go wrong when automating trades through a broker API: bugs, duplicate orders, data failures and connectivity loss, and the safeguards every automated system needs.

Emergency Stop Button (3225255407)
Photo: Tim Regan from Cambridge, UK, CC BY 2.0, via Wikimedia Commons.

Key takeaways

  • Automation can repeat mistakes at speed.
  • Build size, rate and loss limits into code.
  • A kill switch must be reachable and tested.
  • Log, monitor and reconcile positions.

Automation fails differently

A manual trader who makes an error loses one trade. A faulty program can repeat the same mistake hundreds of times in seconds. The more you automate, the more important safeguards become.

Common failure modes

  • Bugs: wrong quantity, wrong side or a loop that sends orders repeatedly.
  • Duplicate orders: a retry after a timeout that actually went through.
  • Bad or stale data: a frozen price feed leading to wrong decisions.
  • Connectivity or API outages: orders placed but not confirmed, or exits that cannot be sent.
  • Credential and token expiry: the system stops without notice.
  • Exchange or broker rule changes: rejected orders.

Safeguards to build in

  • Maximum order size and rate limits in code, independent of strategy logic.
  • Daily loss limit that stops all trading.
  • Idempotent order handling: check order status before retrying.
  • Position reconciliation: compare your internal state with the broker's regularly.
  • Stale data checks: do not trade if the last price is too old.

Kill switches

A kill switch is a way to immediately stop the system, cancel open orders and optionally flatten positions. It should be one command or button that you can reach from your phone, and it should also trigger automatically on conditions such as a daily loss limit or repeated errors. Test it regularly.

Monitoring and logging

Log every decision, order and response. Send alerts for errors, rejections and unusual positions. Review logs after each day so that small anomalies are caught before they grow. Keep the system and secrets secure and never share keys.

Test before going live

Run in a simulator or paper mode first, with failure injection: what happens if the data stops, or an order is rejected? Then start live with tiny size. See paper trading before going live and what is algo trading.

A failure scenario walk-through (illustrative)

Your program sends a sell order for one lot, the broker's API responds slowly and your code times out. Believing the order failed, it retries and sends another order. Both orders had actually been accepted, so you are short two lots instead of one. If your system reconciles positions with the broker every minute, it detects the mismatch and either sends an alert or flattens the extra lot. Without reconciliation, the error persists, and if the same bug repeats on every signal, the position grows. This is why idempotent order handling, unique order tags and position reconciliation are not optional extras but central parts of an automated system.

A pre-launch safety checklist

  1. Hard limits in code: maximum quantity per order, orders per minute, total exposure and daily loss.
  2. A tested kill switch reachable from your phone.
  3. Alerts for errors, rejections, disconnects and stale data.
  4. Daily reconciliation of orders, positions and profit and loss against the broker's records.
  5. Secure storage of API keys and tokens, with no sharing and with expiry handled gracefully.
  6. A written manual procedure for what to do if the system fails during market hours.

Start live trading with the smallest size possible and keep watching it closely for the first weeks. Failures are most likely in the early days and around unusual market events. Combine these safeguards with the strategy checks in building a trading strategy.

Try it yourself — free tools

Frequently asked questions

What is a kill switch in algo trading?

A control that immediately stops the system, cancels orders and, if configured, closes positions, to limit damage from errors.

How do I avoid duplicate orders?

Check the order status before retrying, and use unique identifiers so that a repeated request does not create a second order.

Should an automated system run unattended?

Only with strong safeguards, alerts and daily reviews; many traders monitor closely, especially at first.

Educational content, not investment advice. Trading in options involves substantial risk of loss. Backtested or hypothetical results are not live results and past performance does not guarantee future returns.

Related reading