One of the safest ways to become familiar with retail algorithmic trading is to carry out a procedure known as paper trading. The process involves utilising your backtest and execution system to fire off signals to a brokerage, without the orders actually executing. It allows you to store/retrieve the fake "executed" trades in order to eliminate bugs or other issues with your trading system. Further, it allows you to develop fully-automated execution code against an Application Programming Interface (API).
In this article I will walk through the process of setting up a demonstration account with a popular brokerage known as Interactive Brokers. Why have I picked this particular firm? To be honest it is mainly out of familiarity. I have used the API in a professional fund context before and thus I am well aware of its quirks and particular issues. I was relatively happy with the way that the API allows connectivity via C++, Java and Python.
Once we've setup an account (the easy bit!), we can use a Python library called IBPy to connect to the brokerage and send some orders. The API is rather comprehensive, although somewhat cryptic, as it supports many types of instruments such as equities, futures and options. The API also supports retrieval of market data, but in this case we should expect it to be significantly lagged and somewhat unreliable as we are only connecting with the demo account.
Creating an Interactive Brokers Demo Account
The first thing to do is visit the Interactive Brokers website. We are going to set up a demo account, which means there is no financial obligation whatsoever from us at this stage. We are simply interested in familiarising ourselves with the software.
1) The front page of the Interactive Brokers website
Once at the site select the "Open An Account" link from the drop-down menu on the top-right and then subsequently select "Individual, Joint, IRA and Trust" from the list.
2) Select the "Open An Account" drop-down menu
You'll see two large blue buttons ("FastTrack Application" and "ProTrack Application"). Ignore both! Below them is a button with "Platform Demo. Take it for a spin..." written on it. Select that.
3) Account application screen. Select the "Platform Demo" button.
Once at the Trader Workstation (TWS) Demo page, select the "Try Individual Demo" button.
4) Trader Workstation (TWS) Demo page.
At this point I was sent to the TWS Login page and, at least on my MacBook Air, a file began downloading automatically. I didn't manage to get that particular file installed, so after trying again a few times, I clicked on the link within "If TWS fails to load after two minutes, click here". This allows you to download TWS manually.
5) TWS Login page.
Here you can select whether to use the Browser-Based version of TWS or the standalone download. Since we ultimately wish to use the API, it is necessary to download the standalone version. The process is similar for Windows, Mac and Linux. Make sure to select the corresponding download link depending upon your system.
The only requirement is having the Java Runtime Environment installed, which you are likely to have anyway. If not, you can download that here. The following will be specific to the Mac (as this is the system I'm writing this tutorial on!), but it should be extremely similar for other platforms.
6) TWS download page.
I selected the "Mac Download Latest" button. I imagine there are corresponding choices for various operating systems, so pick the most relevant to your own setup.
7) TWS for Mac download page.
You will then need to follow the instructions as given in the following screen. Essentially I downloaded the package and installed it in the usual way for Mac packages.
8) TWS installation instructions (Mac specific).
This should then start the TWS install screen, at which point you can work through the install wizard.
9) TWS install wizard.
I selected all of the install options when presented with them. IBGateway is a tool that allows you to use the API without the need to load Trader Workstation. I actually found it somewhat fiddly to configure, but this was back in 2010/2011. Things may have changed since then!
10) TWS install options (including IBGateway).
Success! TWS is now ready to be used.
11) Installation complete.
In order to get this functioning on a Mac I had to search for Trader Workstation in the spotlight tool. Once I found it, I added it to my program dock and then ran it. You will be presented with a login screen like the one below. In order to login to the demo account type in edemo as the username and demouser as the password.
12) TWS demo login screen.
The next screen allows you to configure the interface for TWS. I have selected 'Mosiac' for the time being, which provides not only views on orders, but your portfolio and some basic charting functionality. In reality, TWS will be minimised for the vast majority of the time when using it through the API so it isn't particularly crucial how it looks!
13) Configure the interface - Mosaic or Original.
Here is a full screen image of TWS in Mosaic mode. I've selected a chart of the GLD ETF to demonstrate some of the functionality.
14) Full Mosaic interface for TWS.
Now that the demo account has been created and TWS installed, we are ready to configure TWS to handle API access. Once the API has been granted access we can talk to it with IBPy and send some orders. This will be the subject of the next article.