Automating Interactive Brokers Orders with Python and IBPy
Summary
This tutorial explains how a Python program can connect to Interactive Brokers through Trader Workstation (TWS) and the IBPy wrapper. It outlines the client/server API setup, describes callbacks for server errors and replies, and shows how to define a stock contract and an order before submitting it through the connection.
The example sends a single market order to buy 100 shares of Google using SMART routing, then disconnects. The article reports that the order appears in TWS and that the resulting position is visible in the portfolio. This is an execution demonstration rather than a trading strategy or production system: it does not cover signal generation, order monitoring, retries, robust exception handling, or risk controls. The author also notes an unexplained forex position in the demo account, so the observed portfolio contents may not all result from the example trade.
Key ideas
- IBPy wraps the Interactive Brokers API to let Python applications submit orders through TWS.
- A contract specifies the security, exchange, and currency, while an order specifies its type, quantity, and side.
- The example submits a market buy order for Google shares using SMART routing.
- Production systems need stronger error handling and order ID management than this demonstration provides.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.