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”: https://www.youtube.com/channel/UCbY1hA0wpRcbyjBLxI-dxvQ
In following the coding example “HelloWorld.py”, 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/Program.py> 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:
- What is the TWS API?
- Accessing the TWS Python API Source Code.
- Installing & Configuring TWS for the Python API.
- Essential Components of TWS API Programs
- Receiving Market Data and Historical Candlesticks.
- Placing Orders.
- Option Chains, Portfolio Data and Account Info.
- 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:
- Making identical historical data requests within 15 seconds.
- Making six or more historical data requests for the same Contract, Exchange and Tick Type within two seconds.
- 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.***