Connecting an Event-Driven Backtester to Interactive Brokers Execution
Summary
This tutorial adapts an event-driven trading system to submit orders through Interactive Brokers using the IbPy interface. An execution handler consumes order events, builds broker contract and order objects, assigns incrementing order identifiers, and sends orders to the API. It also processes server messages and creates fill events for the system's event queue when an order is reported filled. A dictionary keyed by order ID tracks order details and prevents repeated fill messages from generating duplicate fill events.
The design aims to reuse the backtester’s event structure while replacing simulated execution with broker communication, supporting a later transition toward live trading. The example keeps error handling minimal and uses a fixed initial order ID, so it demonstrates basic integration rather than production-ready execution. A live market data handler is still required, and the article offers no analysis of fills, latency, order routing quality, or execution costs. Its library and API details are specific to the software environment described in the tutorial.
Key ideas
- An execution handler can translate queued order events into broker API orders.
- Broker status messages can be converted into fill events and returned to the system queue.
- Tracking order IDs and fill state helps prevent duplicate fill processing.
- Reusing event-driven components can reduce differences between backtesting and live execution.
- The example has limited error handling and needs a live data feed before it forms a live trading system.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.