Toronto, CANADA / Tokyo, JAPAN
+1 647-303-5547

3- Interactive Brokers Setup

Professional website about Algorithmic Trading and Market Microstructure

Configuration of Interactive Brokers Trader Workstation (TWS):

File > Global Configuration… > API > Settings:

  • Click on <Enable ActiveX and Socket Clients>.
  • Click on <Create API message log file>.
  • Select <Logging level = Warning>.
  • Unselect <Read-Only API>.

According to “Essential Components of TWS API Programs”: before to run any program, we need to include the API module in the Python path. First, download the TWS API and put it in the Python environment (I am using PyCharm). Then, right-click on <TWS/Pythonclient> and select <Mark directory as/Sources root>. For more information, a series of tutorial videos are available titled “Python TWS API”:

In following the coding example “”, we should obtain the below outputs. Please note that <Error -1> messages are not real errors and they reveal that the market data connection is successful because of the <OK>.

The file <TWS/samples/Python/TestBed/> is a complete example of every functionality inside the TWS API. For testing a specific function, the user needs to uncomment one of those lines:

On August 24th, 2018, Interactive Brokers had 8 videos on their playlist and I watched:

  1. What is the TWS API?
  2. Accessing the TWS Python API Source Code.
  3. Installing & Configuring TWS for the Python API.
  4. Essential Components of TWS API Programs
  5. Receiving Market Data and Historical Candlesticks.
  6. Placing Orders.
  7. Option Chains, Portfolio Data and Account Info.
  8. API Case Study in Pair Trades (debug the code provided…).

*** Note: The sample codes are working when following Interactive Brokers’ step. However, running similar commands in a consecutive manner won’t be processed (still investigating this issue). ***

Top Market Data (L1) – reqMktData():

During the tutorials, we learned that <reqMktData> has at least 100 streaming tickers (at the same time). There are limitations in using historical data. “A Pacing Violation occurs whenever one or more of the following restrictions is not observed:

  1. Making identical historical data requests within 15 seconds.
  2. Making six or more historical data requests for the same Contract, Exchange and Tick Type within two seconds.
  3. Making more than 60 requests within any ten minute period.

In addition, API Order has a limitation of 50 messages per song (outgoing) and the Order Efficiency Ratio needs to be less or equal than 20%.

Often, I am successful in using at first <reqMktData()>, but other attempts give empty result (nothing occur). I am currently investigating if it is caused by the paper account itself (port #, etc.).

SMART Routing in Interactive Brokers:

*** Regardless of SMART algorithm selection, for marketable non-directed orders, the multipurpose SMART routing algorithm is always used, except for SMART Dark Only.***