Tutorial: install IBridgePy and run an examples


Tutorial: install IBridgePy and run an example

There is a risk of loss when trading stocks, futures, forex, options and other financial instruments. Please trade with capital you can afford to lose. Past performance is not necessarily indicative of future results.
Nothing in this computer program/code is intended to be a recommendation, explicitly or implicitly, and/or solicitation to buy or sell any stocks or futures or options or any securities/financial instruments.
All information and computer programs provided here is for education and entertainment purpose only; accuracy and thoroughness cannot be guaranteed.
Readers/users are solely responsible for how to use these information and are solely responsible any consequences of using these information.
If you have any questions, please send email to IBridgePy@gmail.com
All rights reserved.

Step 0: Prepare

For Windows users, download and install the latest version of Anaconda, 32-bit or 64-bit Python, either 2.7 or 3.6. It will take up to 30 minutes to download and install Anaconda depending on your internet speed.

For Ubuntu users, please DO NOT install Anaconda.  IBridgePy support Ubuntu native Python 2.7 64-bit.

For Mac usersIBridgePy support either native Python 2.7 64-bit or Anaconda Python 2.7 64-bit.

Step 1:  Download IBridgePy to your local folder

You need to check the version of your Python, either Python 2.7 or Python 3.x and check if it is 32-bit Python or 64-bit Python. Then, download IBridgePy according to your Python version from www.IBridgePy.com/download
Assume the path of the folder where you save IBridgePy is C:\ABC\DEF\IBridgePy

Step 2: Download, install and config IB Trader Workstation(TWS) or IB Gateway

Please follow the instruction in this webpage to download, install and configure IB Gateway or IB Trader Workstation (TWS)

Step 3: Log in TWS or IB Gateway

IBridgePy can trade using either IB live accounts or paper accounts. It is highly recommended to test your strategies in a paper account. If you don’t have an IB account yet, you are welcome to use IB’s public demo account. However, you need to keep it in mind that IB’s public demo account does not behave as same as live accounts or paper accounts do.
User name is “edemo”   —- without quotation marks
Password is “demouser” —- without quotation marks

After you finish this step, either IB Gateway or TWS should be open and active.

Step 4: Spyder is not required to run IBridgePy


Step 5: Edit RUN_ME.py in Spyder

Open RUN_ME.py  (C:\ABC\DEF\IBridgePy\RUN_ME.py) in Spyder.

Put your IB account code into RUN_ME.py


 Step 6: Run your algorithm in Spyder.

Actually, you need to run RUN_ME.py to run your algorithm in Spyder so that you can think RUN_ME.py as a main entrance to any customer’s algorithms. In Spyder, you can click “F5” or the green triangle to run a Python script.


Step 8: Watch out any error messages

After IBridgePy completes its initialization procedures, it will print out a summary of your accounts. If you see a similar summary, it means that IBridgePy gets connected with IB Gateway / TWS successfully.


If you see any error messages, you may follow the error messages to debug.

There are many reasons for errors. You may debug from the following areas:

  1. The bugs come from IBridgePy. We will try our best to fix the bugs coming from IBridgePy.
  2. IB servers may not response as you expect. For example, you may not receive historical data around 6PM eastern time, 1:30 AM eastern time because of IB maintenance or data server updates.
  3. Demo account, paper account and live account behave differently.
  4. Bugs in customer’s algorithms.

11 comments on “Tutorial: install IBridgePy and run an examples
  1. tony says:

    Do I need to uninstall official Python 3.6.4 and Python Launcher before installing Anaconda?

  2. tobyBull says:


    For Mac or Ubuntu user, please DO NOT install Anaconda <– if i don't install Anaconda, how can i download spyder?

    and i hv Python3.6 installed, and IBridgePy is 2.7 for Mac, can it works ?


  3. jklay says:

    Hi, I’ve been trying to make it work in OSX with python 3.6.5 IDLE but it doesn’t work.


    ========== RESTART: /Users/MacMini/Desktop/IBridgePy_Mac/RUN_ME.py ==========
    Traceback (most recent call last):
    File “/Users/MacMini/Desktop/IBridgePy_Mac/RUN_ME.py”, line 36, in
    File “”, line 8, in
    File “/Users/MacMini/Desktop/IBridgePy_Mac/IBridgePy/quantopian.py”, line 1, in
    from IBridgePy import IBCpp
    ImportError: dynamic module does not define module export function (PyInit_IBCpp)

    Can you give me some help??

    thank you so much

  4. yliu31 says:

    Hi Dr. Liu,

    I followed instruction and try to run the first example: example_show_positions.py. But got the following error message:

    brokerName = InteractiveBrokers; dataProviderName = InteractiveBrokers
    runMode = regular
    IBridgePy version 3.1.6
    fileName = example_show_positions.py
    IBridgePy.IBAccountManager:EXIT errorId = -1, errorCode = 326, error message: Unable connect as the client id is already in use. Retry with a unique client id.
    IBridgePy.IBAccountManager:EXIT IBridgePy version = 3.1.6
    An exception has occurred, use %tb to see the full traceback.


    Spyder would not trace the super_configuration.txt file, so I am stuck and don’t know what to do.

    Could you give some clue? I am sure I don’t have a second client trying to access TWS. Shouldn’t an previously exited program automatically release the client id?

    Thanks very much for your help.

  5. yliu31 says:

    Now I understand. The program, once ran, doesn’t really exit, it stays there. So when you try to run it again, the client id is already in use.

  6. mattage86 says:

    I’m getting the following error while attempting to run on a 64 bit Windows 10 with a fresh install of Anaconda. Can you assist?

    File “C:\Users\root\Desktop\IBridgePy_Win_Anaconda36_64\IBridgePy\quantopian.py”, line 5, in
    from IBridgePy import IBCpp

    ImportError: DLL load failed: The specified module could not be found.

  7. bingoboy says:

    I’m getting the following error while attempting to run on a 64 bit Windows 10 with a fresh install of Anaconda. Can you please help?

    IBridgePy.IBAccountManager:EXIT errorId = -1, errorCode = 999, error message: Please download the latest version of IBridgePy at http://www.IBridgePy.com
    IBridgePy.IBAccountManager:EXIT IBridgePy version= 3.2.2

    But on official site I can download only version 3.2.2

Leave a Reply to Anonymous Cancel reply

Your email address will not be published.