Connecting Python to Interactive Brokers and Checking Server Time
Summary
This tutorial introduces the Interactive Brokers native Python API and explains how to establish a basic connection through Trader Workstation or IB Gateway. It describes the API’s asynchronous request and response design, with EClient sending requests and EWrapper handling responses. The example combines derived wrapper and client classes in an application class, then starts the API event loop on a separate thread.
The wrapper places error messages and server time responses in queues. The client requests the current server time and waits up to ten seconds for a response; receiving that timestamp serves as a basic connectivity check. The article assumes the API is already installed and the brokerage application is configured. This is an introductory connection example: it does not cover market data subscriptions, contract definitions, order placement, or production error handling. The provided example focuses on the mechanics of connection and response processing.
Key ideas
- EClient sends requests while EWrapper processes responses from the brokerage server.
- A combined application class can inherit from both client and wrapper subclasses.
- Queues provide a way to collect errors and asynchronous server time responses.
- Requesting server time offers a basic check that the connection is working.
- The example assumes the API and Trader Workstation or IB Gateway are already set up.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.