This website uses cookies to collect usage information in order to offer a better browsing experience. By browsing this site or by clicking on the "ACCEPT COOKIES" button you accept our Cookie Policy.

Duration: 4:00

Level: Intermediate

Contributed By: QuantInsti

In this video, we will explain the Interactive Brokers API architecture and show you how to configure the Trader Workstation.

Read More

Study Notes:

In previous lesson, we listed down the steps for installation of R and Rstudio. The next step is to configure the Trader Workstation (TWS) before we start writing programs in R. This lesson explains the steps required to set up the Trader Workstation.

In this lesson, you would:

  • Learn about the Interactive Brokers API Architecture
  • Learn to configure the Trader WorkStation (TWS)

Interactive Brokers API Architecture

Interactive Brokers provides API solutions which can be run on Windows, Linux, and MacOS. The API makes a connection to the IB Trader Workstation (TWS). The TWS, in turn, is connected to the IB data centers and thus, all the communication is routed via the TWS. The IBrokers R package enables a user to write his strategy/program in R and helps it get executed via the IB TWS.

Flow Structure Diagram

Before we start writing programs in R, we need to configure the Trader Workstation (TWS). The next section explains the steps to configure the TWS.

Steps to Configure the Trader Workstation (TWS)

  • Click on the File tab in Trader Workstation (TWS).
  • Click on the “Global configuration” under the “Application Settings” section.
  • Click on the “API-Settings” under the “Configuration” folder shown on the left-hand side panel.
  • Check the “Enable ActiveX and Socket Clients” box.
  • Check the “Create API message log file” box.
  • Check the ‘Include market data in API log file’ box.
  • Finally, click on the “Apply” shown at the bottom of the API settings page and click OK.

Additional notes

TWS Log Files

If you check the “Create API message log file” box, it will create TWS log files.

  • API message log file contain the exchanged message sequences between the R application and the Trader Workstation.
  • The API message log files will be created within the C drive Jts folder on a Windows system.
  • The TWS logs will be log.[day].txt where day corresponds to the week day when the log file was written.
  • By default, the logging level is set to ‘Error’ which records a minimum amount of diagnostic information.
  • To capture the API messages it necessary to set the logging level to ‘Detail’.

If you also check the ‘include market data in API log file’ box, it will cause real-time market data to be captured in the API when trouble shooting market data problems.

Reset API order Id sequence button

A unique order Id is required every time an order is placed to an account. This unique order Id has to be greater than all the order Ids previously used. The reset button allows resetting the order Id sequence. However, note that this can be done if there are no active orders.


In this lesson, we learned to configure the Trader Workstation (TWS). In the next lesson, we start with the introduction to the IBrokers Package and explain the various API methods available in the package with examples. The subsequent lessons will explain other advanced API methods and finally illustrate an example strategy in R.

Note – The IBrokers package provides native R access to Interactive Brokers Trader Workstation API

Disclosure: Interactive Brokers

The analysis in this material is provided for information only and is not and should not be construed as an offer to sell or the solicitation of an offer to buy any security. To the extent that this material discusses general market activity, industry or sector trends or other broad-based economic or political conditions, it should not be construed as research or investment advice. To the extent that it includes references to specific securities, commodities, currencies, or other instruments, those references do not constitute a recommendation by IBKR to buy, sell or hold such investments. This material does not and is not intended to take into account the particular financial conditions, investment objectives or requirements of individual customers. Before acting on this material, you should consider whether it is suitable for your particular circumstances and, as necessary, seek professional advice.

Supporting documentation for any claims and statistical information will be provided upon request.

Any stock, options or futures symbols displayed are for illustrative purposes only and are not intended to portray recommendations.

Disclosure: R API Disclosure

This software is in no way affiliated, endorsed, or approved by Interactive Brokers or any of its affiliates. It comes with absolutely no warranty and should not be used in actual trading unless the user can read and understand the source. IBrokers is a pure R implementation of the TWS API.

trading top
Translate »