Accessing the TWS Python API Source Code – Accediendo al código fuente de la API TWS Python

The API source code serves the purpose of defining the available messages which can be exchanged between TWS and an external API application.

Figure 1. Source: Model Subscribe/Publish.

It typically uses a subscribe-and-publish pattern, where the API client subscribes to specific data types and TWS publishes real-time updates. The API source code also translates lower-level messages into a more programmer-friendly format.

The importants points about the TWS API include:

  • Open Source and Version Control: The API is open source, managed with Git, and hosted on GitHub. All updates are tracked using Git.

  • Downloads and Resources: Available under Trading > API’s menu on the Interactive Brokers website. This section includes downloads, user guides, release notes, and sample code.

  • Sample Code and Guides: The user guide includes sample code snippets from projects installed in the samples folder (C:TWS APIsamples for Windows and {HOME}/IBJTS for Linux/MacOS).

  • API Release Notes: Updates and new features are documented several times a year in the release notes, accessible from the API resources section.

  • License Agreement: The API has a default non-commercial license, with an option for a commercial license upon request.

  • Python API Requirements: Requires API version 9.81 or higher, with identical source code for Windows and Mac/Linux. The Python API can be installed via MSI Installer or zip file.

  • Public and Private Repositories: Public API downloads are available on interactivebrokers.GitHub.io. Access to the private GitHub repository, which contains the Beta version, is available upon request.

  • Contributions and Issues: Users familiar with Git can contribute via pull requests and raise issues on the GitHub repository.

The API installer on Windows places the API in ´C:TWS API´ and the Python source code in ´C:TWS APIsourcepythonclient´.

Key Components

The TWS Python API source code includes several key components:

  • client.py: Contains the ´EClient´ class, responsible for sending requests to the TWS or IB Gateway.
  • wrapper.py: Contains the ´EWrapper´ class, which handles incoming messages from the TWS or IB Gateway.
  • utils.py: Contains various utility functions used by the client and wrapper classes.

Accede a tu cuenta