Routing Orders to Interactive Brokers with Python and IBPy
Summary
This tutorial describes how a Python program can connect to Interactive Brokers through IBPy, a bridge to the broker’s API, using Trader Workstation or IB Gateway as the intermediary. It explains the client-server setup, the roles of connection and message handling, and how contracts specify details such as symbol, security type, exchange, and currency. It also outlines API configuration, including enabling socket clients and matching the client settings in the program.
The walkthrough demonstrates the structure of a basic order-routing example for an equity, including creating a contract, defining an order, connecting to TWS, handling messages, submitting the order, and disconnecting. It notes that SMART routing can select among available routes and that order identifiers must be unique. This is an integration tutorial rather than a trading strategy: it does not evaluate a signal, execution quality, or profitability. Its setup instructions refer to older Python and IBPy versions, so they may not match current broker interfaces or software requirements.
Key ideas
- IBPy provides a Python interface to Interactive Brokers’ API through TWS or IB Gateway.
- The trading application must connect to the running gateway or workstation with matching API settings.
- An order requires a contract describing the instrument and an order describing the action, type, and quantity.
- SMART routing delegates route selection to the broker’s routing system.
- The example teaches order submission mechanics, not strategy performance or execution quality.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.