Python is one of many programming languages used by algo traders to create a trading strategy. A Python wrapper simplifies a function into a much shorter expression that can be used repeatedly. When programming a trading strategy, one may need to use the same function or series of functions repeatedly, for example to authenticate login credentials, to pull live data, or to place a trade.
Fxcmpy can easily be installed using pip. Once installed, the user will need to obtain an API token for authentication.Once obtained, connection to the REST API can be established in a single line of code:
con = fxcmpy.fxcmpy(config_file='fxcm.cfg', sever='demo')
Once connected, one can begin using the fxcmpy Python wrapper to pull historical and live prices, set entry orders, execute trades and more. Historical data can be pulled in the periods 'm1', 'm5', 'm15', 'm30', 'H1', 'H2', 'H3', 'H4', 'H6', 'H8′,'D1', 'W1' or 'M1' using a single line of code. For example, entering the following line of code will output the high, low, open and close price of the EUR/USD for the past 30 one-minute candles.
data = con.get_candles('EUR/USD', period = 'm1', number = 30)
To create a basic market order, you will provide the instrument and the size of the order (in micro lots) as parameters to either the create_market_sell_order() or create_market_buy_order() methods:
These are just some of the commands available for use.
Senior Market Specialist
Russell Shor (MSTA, CFTe, MFTA) is a Senior Market Specialist at FXCM. He joined the firm in October 2017 and has an Honours Degree in Economics from the University of South Africa and holds the coveted Certified Financial Technician and Master of Financial Technical Analysis qualifications from the International Federation of Technical Analysts. He is a full member of the Society of Technical Analysts in the United Kingdom and combined with his over 20 years of financial markets experience provides resources of a high standard and quality. Russell analyses the financial markets from both a fundamental and technical view and emphasises prudent risk management and good reward-to-risk ratios when trading.