• C#
  • Java
  • VB
  • C++
  • Python
Contact us
Introduction

The TWS API is a simple yet powerful interface through which IB clients can automate their trading strategies, request market data and monitor your account balance and portfolio in real time.

Audience

Our TWS API components are aimed at experienced professional developers willing to enhance the current TWS functionality. Regrettably, Interactive Brokers cannot offer any programming consulting. Before contacting our API support, please always refer to our available documentation, sample applications and Recorded Webinars

How to use this guide

This guide reflects the very latest version of the TWS API -9.72 and higher- and constantly references the Java, VB, C#, C++ and Python Testbed sample projects to demonstrate the TWS API functionality. All code snippets are extracted from these projects and we suggest all those users new to the TWS API to get familiar with them in order to quickly understand the fundamentals of our programming interface. The Testbed sample projects can be found within the samples folder of the TWS API's installation directory.

Requirements

  • • The TWS API is an interface to TWS or IB Gateway, and requires network connectivity to a running instance of one of these programs. • To obtain the TWS API source and sample code, download the API Components.
    • To make use of TWS API 9.72+, will require TWS build 952.x or higher.
    • A working knowledge of the programming language our Testbed sample projects are developed in.
  • • To obtain the TWS API source and sample code, download the API Components.
    • To make use of TWS API 9.72+, will require TWS build 952.x or higher.
    • A working knowledge of the programming language our Testbed sample projects are developed in.
    • Java 8 or higher is required for running the Java API client.
  • • To obtain the TWS API source and sample code, download the API Components.
    • To make use of TWS API 9.72+, will require TWS build 952.x or higher.
    • A working knowledge of the programming language our Testbed sample projects are developed in.
    • Microsoft .Net Framework 4.5 or higher is required for running the VB API client.
  • • To obtain the TWS API source and sample code, download the API Components.
    • To make use of TWS API 9.72+, will require TWS build 952.x or higher.
    • A working knowledge of the programming language our Testbed sample projects are developed in.
    • A compiler that supports C++11 is required for running the C++ API client.
    • For Windows users who use Visual Studio, a version of 2012 or higher is required.
  • • To obtain the TWS API source and sample code, download the API Components (API version 9.73 or higher is required).
    • To make use of TWS API 9.73+, will require TWS build 952.x or higher.
    • A working knowledge of the programming language our Testbed sample projects are developed in.
    • Python version 3.1 or higher is required to interpret Python API client.

Limitations

Our programming interface is designed to automate some of the operations a user normally performs manually within the TWS Software such as placing orders, monitoring your account balance and positions, viewing an instrument's live data... etc. There is no logic within the API other than to ensure the integrity of the exchanged messages. Most validations and checks occur in the backend of TWS and our servers. Because of this it is highly convenient to familiarize with the TWS itself, in order to gain a better understanding on how our platform works. Before spending precious development time troubleshooting on the API side, it is recommended to first experiment with the TWS directly.

Remember: If a certain feature or operation is not available in the TWS, it will not be available on the API side either!

Requests

The TWS is designed to accept up to fifty messages per second coming from the client side. Anything coming from the client application to the TWS counts as a message (i.e. requesting data, placing orders, requesting your portfolio... etc.). This limitation is applied to all connected clients in the sense were all connected client applications to the same instance of TWS combined cannot exceed this number. On the other hand, there are no limits on the amount of messages the TWS can send to the client application.

Paper Trading

If your regular trading account has been approved and funded, you can use your Account Management page to open a Paper Trading Account which lets you use the full range of trading facilities in a simulated environment using real market conditions. Using a Paper Trading Account will allow you not only to get familiar with the TWS API but also to test your trading strategies without risking your capital. Note the paper trading environment has inherent limitations.

Intel® Decimal Floating-Point Math Library

This product includes Intel® Decimal Floating-Point Math Library (in binary form) developed by the Intel Corporation under its license which can be found here.

  • Decimal type (source/cppclient/client/Decimal.h)
    All operations with Decimal type should be performed with Intel® Decimal Floating-Point Math Library.
    Currently the following methods from the library are exposed: add, sub, mul, div, stringToDecimal, decimalToString, decimalStringToDisplay, decimalToDouble and doubleToDecimal.
    All other methods can be exposed on demand.

    Details of exposed methods:
    Decimal add (Decimal, Decimal) - adds two decimal values. Returns decimal result of operation.
    Decimal sub (Decimal, Decimal) - subtracts the second decimal value from the first. Returns decimal result of operation.
    Decimal mul (Decimal, Decimal) - multiplies two decimal values. Returns decimal result of operation.
    Decimal div (Decimal, Decimal) - divides the first decimal value by the second. Returns decimal result of operation.
    Decimal stringToDecimal (std::string) - converts string to decimal value.
    std::string decimalToString (Decimal) - converts decimal value to string. String can have scientific notation.
    std::string decimalStringToDisplay (Decimal) - converts decimal value to string without scientific notation.
    double decimalToDouble (Decimal) - converts decimal value to double value. Note: conversion of decimal to double may lose 16th-18th decimal.
    Decimal doubleToDecimal (double) - converts double value to decimal value.

linkarrow_external.png
Links pointing to sources out of this documentation are indicated it as such