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, Anaconda Python is required. Python 2.7 or 3.6 or 3.7.
- For your convenience, use this link Anaconda3-5.0.1-Windows-x86_64.exe to download Anaconda Python 3.6 for windows users.
- Use this link Anaconda2-5.0.1-Windows-x86_64.exe to download Anaconda Python 2.7 for windows users.
For Ubuntu users, please DO NOT install Anaconda. IBridgePy supports Ubuntu plain Python 2.7 or 3.7 64-bit.
For Mac users, IBridgePy supports plain Python 2.7 64-bit, plain Python 3.7 64-bit and Anaconda Python 2.7 64-bit.
Note: The following steps are for Windows users. For Ubuntu and Mac users, we are working on other tutorials.
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 can apply a paper account. After you finish this step, either IB Gateway or TWS should be open and active.
Step 4: Spyder is not required to run IBridgePy
Spyder is not required but it is recommended for Windows users. Other IDEs can be used as long as the correct Python executable file is used.
Step 5: Edit RUN_ME.py in Spyder (Spyder is not required, for demo purpose only)
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:
- 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.