2. Server Connection

This section is about the server and API connection itself. It needs to be established before any other tasks can be accomplished.

The following assumes that you have created a configuration file with your credentials as described in the Quick Start section.

In [1]:
import fxcmpy
In [3]:
con = fxcmpy.fxcmpy(config_file='fxcm.cfg')

2.1. Status Information

To check if the connection is established, you can use the method con.is_connected().

In [4]:
con.is_connected()
Out[4]:
True

After the connection is established, fxcm.py gathers information about your FXCM account.

For example, the ids of your accounts within your FXCM account are retrieved.

In [5]:
con.get_account_ids()
Out[5]:
[2815291]

The first account `id`` is used as default:

In [6]:
con.get_default_account()
Out[6]:
2815291

To set another account as default, use con.set_default_account().

In [7]:
con.set_default_account(2815291)

The ids of your existing orders from previous sessions are also available …

In [8]:
con.get_order_ids()  # regular orders
Out[8]:
[94110644, 95845790, 95841449]
In [9]:
con.get_oco_order_ids()  # OCO orders
Out[9]:
[]

… as well as the available instruments.

In [10]:
instruments = con.get_instruments()
print(instruments)
['EUR/USD', 'USD/JPY', 'GBP/USD', 'USD/CHF', 'EUR/CHF', 'AUD/USD', 'USD/CAD', 'NZD/USD', 'EUR/GBP', 'EUR/JPY', 'GBP/JPY', 'CHF/JPY', 'GBP/CHF', 'EUR/AUD', 'EUR/CAD', 'AUD/CAD', 'AUD/JPY', 'CAD/JPY', 'NZD/JPY', 'GBP/CAD', 'GBP/NZD', 'GBP/AUD', 'AUD/NZD', 'USD/SEK', 'EUR/SEK', 'EUR/NOK', 'USD/NOK', 'USD/MXN', 'AUD/CHF', 'EUR/NZD', 'USD/ZAR', 'USD/HKD', 'ZAR/JPY', 'USD/TRY', 'EUR/TRY', 'NZD/CHF', 'CAD/CHF', 'NZD/CAD', 'TRY/JPY', 'USD/CNH', 'AUS200', 'ESP35', 'FRA40', 'GER30', 'HKG33', 'JPN225', 'NAS100', 'SPX500', 'UK100', 'US30', 'Copper', 'EUSTX50', 'USDOLLAR', 'USOil', 'UKOil', 'NGAS', 'Bund', 'XAU/USD', 'XAG/USD']