Migrating from Quantopian to IBridgePy can be very easy in some cases even without making any code changes. In this thread, I am going to talk about how to make the migration as smooth as possible. In the following, I will explain the detailed steps assuming you are using a Microsoft Windows system.
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. 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: Complete preparation steps
Please follow the instruction in this webpage http://www.ibridgepy.com/preparation/ to install Anaconda (Do NOT install Anaconda for Mac and Ubuntu users), install IB Gateway or TWS and set up Python Path in Spyder.
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 “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 3: Copy and Save your Quantopian algorithms
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
Add one line in RUN_ME.py -> fileName = ‘MyAlgo.py’
Set runMode = ‘run_like_quantopian’
Step 5: Check what Quantopian functions you are using in your algorithm
The Quantopian functions that are supported by IBridgePy are listed here. These functions are supposed to behave as similar as they do in Quantopian. You are welcome to send an Email to IBridgePy@gmail.com if you find out that any functions perform very differently. We will try our best to fix them.
* You need to delete any Quantopian functions that are not supported by IBridgePy in your algorithms. As of Aug 27th 2017, IBridgePy does not support Quantopian’s pipeline yet.
* You need to install any 3rd part Python packages that you are using in your algorithms, for example, TaLib, if these 3rd part Python packages are not automatically installed with Python XY or Anaconda. As an example, pytz is a Python package to handle time zones and it has been automatically installed with Python XY or Anaconda so that you don’t need to install it again.
- 1.1 initialize — similar as initialize at Quantopian
- 1.2 handle_data — similar as handle_data at Quantopian
- 1.3 before_trading_start — similar as before_trading_start at Quantopian
- 1.4 Data method — similar as Data method at Quantopian
- 1.5 data.current — similar as data.current at Quantopian
- 1.6 data.history — similar as data.history at Quantopian
- 1.7 order — similar as order at Quantopian
- 1.8 order_target — similar as order_target at Quantopian
- 1.9 order_percent — similar as order_percent at Quantopian
- 1.10 order_target_percent — similar as order_target_percent at Quantopian
- 1.11 order_value — similar as order_value at Quantopian
- 1.12 order_target_value — similar as order_target_value at Quantopian
- 1.13 cancel_order — similar as cancel_order at Quantopian
- 1.14 get_open_orders — similar as get_open_orders at Quantopian
- 1.15 get_order — similar as get_order at Quantopian
- 1.16 get_datetime — similar as get_datetime at Quantopian
- 1.17 symbol — similar as symbol at Quantopian
- 1.18 symbols — similar as symbols at Quantopian
- 1.19 schedule_function– similar as schedule_function at Quantopian
- 1.20 record — similar as record at Quantopian
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 7: 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 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:
- The bugs come from IBridgePy. We will try our best to fix the bugs coming from IBridgePy.
- 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.
- Demo account, paper account and live account behave differently.
- Bugs in customer’s algorithms.