@

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

Any opinions, news, research, analyses, prices, other information, or links to third-party sites contained on this website are provided on an "as-is" basis, as general market commentary and do not constitute investment advice. The market commentary has not been prepared in accordance with legal requirements designed to promote the independence of investment research, and it is therefore not subject to any prohibition on dealing ahead of dissemination. Although this commentary is not produced by an independent source, FXCM takes all sufficient steps to eliminate or prevent any conflicts of interests arising out of the production and dissemination of this communication. The employees of FXCM commit to acting in the clients' best interests and represent their views without misleading, deceiving, or otherwise impairing the clients' ability to make informed investment decisions. For more information about the FXCM's internal organizational and administrative arrangements for the prevention of conflicts, please refer to the Firms' Managing Conflicts Policy. Please ensure that you read and understand our Full Disclaimer and Liability provision concerning the foregoing Information, which can be accessed here.

Risk Warning: Our service includes products that are traded on margin and carry a risk of losses in excess of your deposited funds. The products may not be suitable for all investors. Please ensure that you fully understand the risks involved.