@

How does a Python wrapper simplify the process of coding an algo?

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. This article from QuantNews illustrates how traders can accomplish these tasks in a few lines or even a single line of code using the fxcmpy Python wrapper.

Fxcmpy can easily be installed using pip. Once installed, the user will need to obtain an API token for authentication. A guide to creating your API token can be found here. 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:

con.create_market_buy_order('USD/JPY', 10)

These are just some of the commands available for use. For more information about fxcmpy and its capabilities, read the full documentation located here.

Disclosure

These materials constitute marketing communication and do not take into consideration your personal circumstances, investment experience or current financial situation. The content is provided as general market commentary and should not be construed as containing any type of investment advice, investment recommendation and/or a solicitation for any investment transactions. This market communication does not imply or impose an obligation on you to perform an investment transaction and/or purchase investment products or services. These materials have not been prepared in accordance with legal requirements designed to promote the independence of investment research and are not subject to any prohibition on dealing ahead of the dissemination of investment research.

FXCM, and any of its Affiliates, shall not in any way be liable to you for any inaccuracies, errors or omissions, regardless of cause, in the content of these materials, or for any damages (whether direct or indirect) which may arise from the use of such materials, services and their content. Consequently, any person acting on them does so entirely at their own risk. Please ensure that you read and understand our Full Disclaimer and Liability provision concerning the foregoing Information, which can be accessed here.