Algo Trading with REST API and Python | Part 1: Preparing Your Computer

Welcome to our Instruction Series about using FXCM’s REST API to automate your strategies using Python. In this multi-part series we will dive in-depth into how algorithms are created, starting from the very basics.

In this article you will learn how to prepare your computer for algo trading with REST API and Python. If you have already prepared your computer, please feel free to skip ahead.

STEP 1: INSTALL PYTHON

As mentioned before, for our tutorial series we will be using Python version 3.6 to connect to the FXCM REST API. Python is one of the most widely used programming languages for most individual traders. With that said, one of the benefits of FXCM’s REST API is that it will work with almost any programming language. You can find documentation and tutorials for other languages by visiting FXCM’s Github.

Installing Python and the necessary packages is a fairly straight-forward process. To make things even easier, we will be using the Anaconda Distribution installer, which will installs most of the packages that are needed in order to use the REST API, including Python itself and the always useful Jupyter. As mentioned before, this tutorial will utilize Python version 3.6 which can be downloaded from the Anaconda website, www.anaconda.com/download. To do download Anaconda, simply click on the download button.

Open and run the installation wizard that appears in your browser. The default settings in the installation wizard work well most of the time, but if you run into any issues Anaconda has a great installation guide here.

STEP 2: INSTALL NECESSARY PACKAGES

Once the install wizard has finished, launch the Anaconda Navigator by going to the Windows start menu and selecting Anaconda Navigator. Once open, search the ‘environments’ tab to find out if the necessary packages have already been installed. Some packages, like Pandas and requests, should already be installed and will appear when searched for as shown below:

Requests and Pandas should already be installed, but the last library you will need for this tutorial, SocketIO, will need to be installed separately. To install the SocketIO package, go back to the start menu and launch the Anaconda Prompt. You can find the Anaconda Prompt in the same folder as Anaconda Navigator. In this prompt, install the correct version of SocketIO by typing the following and hitting enter:

pip install -U socketIO-client

If the socketIO installation was successful, you will see a message indicating so, similar to the one below. Those are all of the packages needed at this time, so you can close the window.

STEP 3: OPEN JUPYTER

Now that everything is installed, it’s time to ensure everything is working properly. Open a Jupyter Notebook through the Anaconda Prompt to check on the packages installed in step 2. To open a Jupyter notebook, navigate to your Anaconda 3 folder, open the Anaconda Prompt, type in jupyter notebook and hit enter. This will open Jupyter as a new tab on your Internet browser. Click New and select Python 3 as the notebook type as shown below:

Now you have opened a Jupyter notebook in which you can execute python code. You can check and make sure that all of the packages have been installed properly by importing them. To do that, type the following:

import pandas as pd
import json
import requests
from socketIO_client import SocketIO

Then hit shift+enter to run this cell and execute the code. You should not receive any error messages, indicating the packages were able to be imported, meaning they were installed properly. If you do get an error, ensure your code was entered correctly, including proper spelling and capitalization. If the error persists, feel free to reach out to us at api@fxcm.com for help.

And that’s it! Your computer is now prepped and ready to connect to the FXCM REST API. In the next tutorials, we’ll be utilizing this same Jupyter Notebook to learn how to establish a connection to the FXCM REST API server, authenticate with our demo account credentials, build a function to retrieve and display live streaming prices, and then create a strategy to execute orders based off of this live streaming data. Click below to continue to the part 2.

Continue to Part 2


Risk Warning: The FXCM Group does not guarantee accuracy and will not accept liability for any loss or damage which arise directly or indirectly from use of or reliance on information contained within the webinars. The FXCM Group may provide general commentary which is not intended as investment advice and must not be construed as such. FX/CFD trading carries a risk of losses in excess of your deposited funds and may not be suitable for all investors. Please ensure that you fully understand the risks involved.