Skip to content
All library documents

Connecting an Event-Driven Backtester to Interactive Brokers for Order Execution

Article FMZ forum · Author: 善

Summary

This tutorial explains how to replace a simulated execution handler in an event-driven trading system with one that submits orders through Interactive Brokers using IbPy. The handler receives order events, builds contract and order objects, sends them to the broker connection, and processes server messages. It tracks order IDs and stores order details so that a fill event can be returned to the system’s event queue when a filled status arrives.

The article shows how to register message handlers, define contracts and orders, and link broker fills back into the strategy architecture. It emphasizes reusing the same event-driven structure for backtesting and live trading. The implementation is explicitly introductory: error handling and execution optimization are left out, the example uses a fixed initial order ID, and a live market data handler is still needed. The code also includes a one-second pause after order submission based on the author’s experience; this is not presented as a general guarantee of reliable execution.

Key ideas

  • An Interactive Brokers execution handler can consume order events and submit corresponding broker orders.
  • Broker replies can be converted into fill events and returned to the shared event queue.
  • Tracking order IDs and fill status helps prevent duplicate fill events.
  • The example omits robust error handling and execution optimization, and it still requires a live market data component.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.