Tutorial: Migrating from Quantopian to IBridgePy

Migrating from Quantopian to IBridgePy can be very easy in some cases even without making code changes. This comprehensive guide will help you understand the process of migrating from Quantopian to IBridgePy as smooth as possible using Python stock trading with Interactive Brokers for algorithmic trading.

As a short description, in the runMode of run_like_quantopian, the initialize function will run once at the beginning of the algorithm and handle_data function will run every minute, just like how they perform at Quantopian.

EXCLUSIVE OFFER

Extra 7% OFF All Quantra Courses

Level up your quant trading skills with courses from Quantra by QuantInsti — Python for trading, machine learning strategies, options trading, and more.

HUI7 Browse Courses → Use code HUI7 at checkout

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. When migrating from Quantopian, 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




Need help building this strategy?

Our Rent-a-Coder team builds custom automated trading programs. From simple scripts to complex multi-account strategies — we handle it all.

Step 2: Complete preparation steps

step 2. 1 Install Anaconda

For Windows users, Anaconda is required.

For Ubuntu users, do NOT install Anaconda. You need to use native Python 2.7 64-bit

For Mac users, you can choose to install Anaconda or not. You may refer to this tutorial to debug on Mac if any issues.

step 2.2 Configure TWS or IB Gateway

The detailed steps are described in this webpage.

Configure TWS or IB Gateway

step 2.3 Log into IB TWS or IB Gateway

IBridgePy can trade in IB live accounts and 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, IB’s public demo account does not behave as same as live accounts or paper accounts do.
User name is “fdemo” —- 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 3: Copy and Save your Quantopian algorithms

Migrating from Quantopian to IBridgePy strategies folder

Save your Quantopian algorithms in a folder called “Strategies” that is a sub-folder of IBridgePy (C:\ABC\DEF\IBridgePy\Strategies). The file extension should be “.py” because they are Python scripts. In the following, assume the file name of your algorithm is MyAlgo.py , and it is saved at C:\ABC\DEF\IBridgePy\Strategies\MyAlgo.py




Step 4: 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

migrating to ibridgepy runme

EXCLUSIVE OFFER

Extra 7% OFF All Quantra Courses

Level up your quant trading skills with courses from Quantra by QuantInsti — Python for trading, machine learning strategies, options trading, and more.

HUI7 Browse Courses → Use code HUI7 at checkout

Ready to Automate Your Trading?

Download IBridgePy free or let our coders build your strategy.

Download Free Hire a Coder

37 thoughts on “Tutorial: Migrating from Quantopian to IBridgePy”

          1. they have an unofficial api. I don’t believe partner status is really needed, they will be rolling out an official api here soon and it would be really nice to not have to migrate code.

  1. Following mail sent yesterday (traceback,last line:
    File “C:\Python27\lib\site-packages\IPython\core\ultratb.py”, line 617, in _format_exception_only
    Colors.Normal, s))

    UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xf3 in position 38: ordinal not in range(128)
    Any sugestion?
    I am installing and trying to connect thru run_me.py and getting historical data

  2. Anyone here have any success experience running the IBridgePy in Ubuntu with https://ibridgepy.com//wp-content/uploads/2017/09/IBridgePy_ubuntu.zip

    I’m hitting the following roadblock:
    Traceback (most recent call last):
    File “RUN_ME.py”, line 35, in
    exec(script)
    File “”, line 8, in
    File “/root/ib-api/IBridgePy/IBridgePy/quantopian.py”, line 1, in
    from IBridgePy import IBCpp
    ImportError: /root/ib-api/IBridgePy/IBridgePy/IBCpp.so: undefined symbol: GENERAL_NAME_free

    Any idea what went wrong? The following is my python environment:
    Python 2.7.12 (default, Nov 19 2016, 06:48:10)
    [GCC 5.4.0 20160609] on linux2
    Type “help”, “copyright”, “credits” or “license” for more information.
    >>> import struct
    >>> print(8 * struct.calcsize(“P”))
    64

    Thanks in advance.

  3. Has order_target_percent been implemented? Don’t see any references to it in the release notes.

    I am running an algo but it hasn’t placed any orders yet so I am worried that it will fail when it comes onto that command.

  4. Hi,

    I read the Tutorial again and have the following questions:

    1. before_trading_start
    >>The time when before_trading_start is called can be configured by users.

    In the ‘configuration.txt’? But how?

    2. sid()
    Do you support the sid() as in Qauntopian?

    3. Order types
    It seems you have only three order functions: oder(), order_target() and order_percent(). How about the others as by Quantoipian such like: order_value(), order_target_value() and order_target_percent()

    4. ocaGroup in create_order()
    Seems the oca = oco (one cancle the other), right?

    5. Relation betwwen create_order() and place_combination_orders()
    I understand one has to use the create_order() to create order legs and then use the place_combination_orders() to place these legs. Correct?

  5. Hi,

    Looking forward to trying this out. Just installed and setup everything, will try porting over my algo today and running for the next few days.

    Qustion: How do we run multiple algos? Do we clone RUN_ME.py for each algo and run them simultaneously? Example: RUN_ME_algo1.py, RUN_ME_algo2.py, etc.

    Thank you.

      1. This means you run multiple algos on a single account. I am not sure if this is a good idea.

        The best way is to run single algo on single account, the so-called multiple account. But you would chage for that. :-/

  6. I can’t get historical data for some etfs. Is there a exhaustive list of security_info.csv?
    For e.g. I can’t get prices for EWG
    Also, if I want the index price for Shanghai index , or SENSEX what should I do?

  7. I simply cloned an algo from quantopian to see if I could figure this all out. I have IB, everything nearly set. Forgive my ignorance as im no expert at this but I get an error “no module: quantopian.pipeline.data.builtin” What do I do?

Leave a Comment