Exclusive 22% OFF All Quantra by QuantInsti Courses for IBridgePy Users Master algorithmic trading from beginner to advanced — Python for trading, machine learning strategies, options trading, and more.
HUI22 Use HUI22 for 22% off
HUI7 Stack HUI7 for an additional 7% off
Browse Courses →
← Back to Blog

Tutorial: Migrating from Quantopian to IBridgePy

August 27, 2017

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.

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




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