How to enable Python API in Interactive Brokers Trader Workstation

You’re going to want to open Interactive Brokers trader workstation as normal. Then head over to edit>Global Configuration and check that first box.

Enable ActiveX and Socket Clients

The next thing you’ll want to download is the API’s found here – http://interactivebrokers.github.io/

Next, open the command prompt as an administrator and switch directories where you installed it.

d:

D:\TWS API\source\pythonclient

python setup.py install

You will see this if it is completed successfully

Installed c:\program files\python39\lib\site-packages\ibapi-9.76.1-py3.9.egg
Processing dependencies for ibapi==9.76.1
Finished processing dependencies for ibapi==9.76.1

D:\TWS API\source\pythonclient>

I use IntelliJ to to test I’m going to run a simple command

import ibapi

You can see it ran successfully.

So let’s test a little further.

I’m going to run the following Python code

import ibapi

from ibapi.client import EClient
from ibapi.wrapper import EWrapper

class IBapi(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)

app = IBapi()
app.connect('172.16.105.5', 7496, 123)


app.run()

import time
time.sleep(2)
app.disconnect()

This shows it was successful

“C:\Program Files\Python39\python.exe” “G:/My Drive/IdeaProjects/interactive_brokers/interactive_brokers_api_test.py”
ERROR -1 2104 Market data farm connection is OK:usfarm.nj
ERROR -1 2104 Market data farm connection is OK:cashfarm
ERROR -1 2104 Market data farm connection is OK:usfarm
ERROR -1 2106 HMDS data farm connection is OK:euhmds
ERROR -1 2106 HMDS data farm connection is OK:fundfarm
ERROR -1 2106 HMDS data farm connection is OK:ushmds
ERROR -1 2158 Sec-def data farm connection is OK:secdefnj

Facebook Comments Box

Leave a Reply