Communicating with Interactive Brokers API (Python)

Corbin Balzan
The Startup
Published in
12 min readFeb 5, 2020

Photo by Fabian Grohs on Unsplash


This article is the first part in a series of Interactive Brokers API tutorials. This section shows the initial steps of setting up the code and getting started with the Trader Workstation connection and your own systemic trading program.

Article Source:

The article is based onGuide To Interactive Brokers

Relevant Resources:

Program Overview

To begin programming with the Interactive Brokers API, it is first essential to understand the API information exchange. Our program will be broken up into nine parts:

1) Import statements: This section defines the classes we will import from relative locations in the file tree.

2) Global Variables: These will be used to store and access values throughout the program.

3) Custom classes and methods: These classes and methods will be created as we go along in the program on an as-needed basis.

4) TestWrapper Class: This class implements EWrapper Interface and handles the returns from our server requests. In other words, this is the GET part of the information exchange. This is where we will receive and handle information from the TWS by overriding API functions.

5) TestClient Class: This class implements the ClientSocket and sends the request we will make to the server. This is the POST part of the information exchange. In this section, we will invoke functions to send messages to the TWS.

6) TestApp: Where we will establish environmental variables, algorithm preferences, and initialize the program.

7) Execution: The call to program start and begin the algorithm

8) Input area: Where we connect to an input source and receive incoming information

9) Processing area: Where we will interpret the input source and deliver our decision to the correct Interactive Brokers object.

Throughout this tutorial, the code will be written in a file named…

Corbin Balzan
The Startup

Technology & Consulting

Recommended from Medium


See more recommendations