almost 7 years ago
Update 1/14: The submission deadline has been extended to February 28, 2013.
Welcome to the final month of the FXCM Freestyle App Challenge! The submission deadline is January 24. If you haven’t started yet, check out the Quick-Start Guide and begin exploring the ForexConnect API today.
For those of you who are working on a build, here are some helpful tips on the API that will save you some time and lines of code:
Develop for Multiple Accounts
The O2GAccountsTable will contain one O2GAccountRow for each trading account that is accessible to the username (LoginID). Indeed most users only access one account, but it is not uncommon to have multiple accounts under one username. Your application design should be deliberate in the way it handles the existence of multiple accounts.
Unless it is absolutely necessary to support one account alone, it is advisable that you develop with multiple accounts in mind. Converting your application later to support multiple accounts will lead to hours of refactoring.
Know User Permissions
The largest differentiator between trading accounts types is position maintenance. In order to avoid minimizing your user base, your application should not be agnostic to this.
Put simply, FXCM US account types cannot use hedging. This means they cannot simultaneously hold both Buy and Sell positions in the same symbol. Generally all other accounts can use hedging. This is significant and it impacts the way you can close positions on these accounts.
Checking for Hedging Status
To check for hedging status, refer to the O2GAccountRow.MaintenanceType Property in the O2GAccountsTable. If this Property returns a value of “Y,” hedging is enabled. If it returns anything other than “Y,” hedging is disabled.
Closing Positions – Hedging Disabled
With hedging disabled, you cannot simultaneously hold both Buy and Sell positions in the same symbol. As a result, this means that Buy and Sell orders cancel each other out. To close an existing position, you simply send an order in the opposite direction.
Closing Positions – Hedging Enabled
With hedging enabled, you close positions by sending a CreateOrder command with OrderType set to “C” for Close. This API call will also include a TradeID parameter that is used to indicate which position you are attempting to close. The ForexConnect download comes with examples that demonstrate how to do this.
Use O2GTableManager when Necessary
While an active connection is maintained, the ForexConnect API will automatically request from the trade server updates to the O2GTable objects. You will see that by simply implementing a response listener class (via IO2GResponseListener), these updates are automatically captured in the IO2GResponseListener.onTablesUpdates callback. You do not need to write any code to request these updates.
Two options exist to process these automatic updates: IO2GResponseListener and O2GTableManager.
A response listener class merely exposes methods which capture the updates. It adds no additional network or memory overhead. The drawback, however, of using IO2GResponseListener is that it does not provide for “calculated fields.” In other words, the updates you capture in onTablesUpdates have the contents (rows) of each table and their constant fields. For example, O2GTradesTable updates will have Symbol, Open Price, and other constant fields whose values do not depend on a floating price. P/L would be an example of a “calculated field” that is entirely dependent on the current market price.
The table manager object, if you choose to use it, maintains an in-memory representation of all the tables and their calculated fields. For example, using O2GTableManager will give you access to a trades table object which contains the P/L field. The benefit to this option is obvious. Having access to calculated fields such as P/L, Gross P/L, and Account Equity reduces your programming effort. However, the drawback of this method is the increased memory overhead.
O2GTableManager should only be used when you rely on many calculated fields. Your own application development would impact memory consumption in a similar way. If, however, your demands for these calculated values come at lower frequency or you simply refer to less of them, it is advisable to use IO2GResponseListener and calculate internally what you need, on a Just-In-Time basis.
If you have any technical questions or would like to share feedback on the API, please visit the FXProgrammers Forum or email firstname.lastname@example.org. For questions about the challenge, email email@example.com and include "FXCM" in the subject line.