Rest Quick Start Guide Python
Rest Quick Start Guide Python
1. Overview:
FXCM offers a web-based REST API which can be used to establish secure connectivity with FXCM’s
trading systems for the purpose of receiving market data and trading.
This document provides the easiest way to use the REST API for the basic steps of trading.
To get started with the API and the example code, a demo account with FXCM is sufficient. You can open
such an account under https://www.fxcm.com/uk/forex-trading-demo/. Also a PyCharm(IDE for python)
and Anaconda version 3 should be installed. Python 3.6 is the version that is used in the sample.
2. Prerequisite:
- A token should be revoked from the Trading Station on
https://tradingstation.fxcm.com/
- The Socked.IO library should be installed using Python:
https://pypi.python.org/pypi/socketIO-client
- The Python Example should be cloned or downloaded and loaded into the PyCharm
from https://github.com/fxcm/fxcm-api-rest-python3-example
3. Get connected.
In order to connect you should perform the following steps:
- Add the following imports to the project as it is shown in the
“fxcm_rest_api_token.py” file from the https://github.com/fxcm/fxcm-api-rest-
python3-example:
from collections import namedtuple
import requests
from socketIO_client import SocketIO
import logging
import json
import uuid
import threading
from dateutil.parser import parse
from datetime import datetime
import time
import types
- Link your account through the account token that you have revoked from
https://tradingstation.fxcm.com/
trader = fxcm_rest_api.Trader(’YOUR_TOKEN_HERE’, 'demo') # demo for demo
trader.login()
For the example purposes we will enter the following rows and the previous imports will be used
through the “fxcm_rest_api_token”:
import fxcm_rest_api_token
trading_symbol = 'EUR/USD'
trader = fxcm_rest_api_token.Trader(YOURTOKEN , 'demo') # demo for demo
trader.login()
trade_amount = 10
trade_start_buy_price = SHOULD BE MUCH LOWER THAN THE CURRENT PRICE
trade_start_sell_price = SHOULD BE MUCH HIGHER THAN THE CURRENT PRICE
live_feed = trader.subscribe_symbol('EUR/USD')
print(live_feed)
As an only parameter you need to enter the symbol you are trading
Parameters:
6.1.
theAccountID = trader.account_id
6.2.
open_positions = trader.open_positions
for position in open_positions:
print(position)
6.3.
closed_positions = trader.closed_positions
for position in closed_positions:
print(position)
Parameters:
- theAccountID you can extract as shown in step 6.1
- trading_symbol is the symbol you will start a trade in
- True actually stand there as an answer of the question if this is going to be a BUY
trade or a SELL trade
- 10 is the amount of lots you are going to trade
Parameters:
If you want to change the parameters of an entry order you have to use the ID and this is how
you extract them:
open_orders = []
orders = trader.orders
for order in orders:
open_orders.append(order['orderId'])
Parameters: