Myfxbook provides an interface to your FOREX trading accounts as well as an active trading community. It has a broad range of functionality including
a responsive interface to the FOREX market;
tools for performing statistical analyses on your trades;
the facility to mirror trades from other traders or systems; and
provides a platform for publicising trading systems.
R Interface to the API
There is an API which facilitates direct programmatic access to your Myfxbook account. You access the API via HTTP GET requests and it returns the results either as XML or JSON. I have taken advantage of R’s web technologies to build an interface with Myfxbook. I implemented the interface as a reference class which exercises most of the calls in the API.
The first thing we need to do is connect to Myfxbook. To do this we create an instance of the reference class. The class constructor takes an email address and password as arguments. The API returns a session identifier which is then retained as a data member in the class. For security reasons the email address and password are not retained.
We can get the details for the accounts which we have linked to the system. I have just hooked up a single demo account for the purposes of this article.
And we can also see the status of other accounts which we are watching.
There is an interface to the community outlook data, which gives an indication of the number and volume of trades as a function of currency pair.
To get a feeling for the relative proportion of long and short trades across all currencies we can put together an informative plot. It requires a little leg work first though to get the data into a workable format:
melt the data frame into a “tidy” format, extracting only the columns for the percentage of long and short trades;
normalise the percentages (given as integers which do not all sum to 100%);
remove entries with missing data;
neaten up labels for long and short percentages; and
sort according to fraction of shorts.
The outlook data can also be broken down by country for a single currency pair.
As before, making sense of this is aided by a visualisation. Below is a plot showing the number of long and short positions on EURUSD for a range of countries. We can see that overall the most trades have originated in Spain and Russia and that the majority of these positions are shorts.
We can also get a list of our open trades and pending orders.
Here the argument is a Myfxbook account number, which is either found on your dashboard (see image below) or from the id field in the output from my.accounts() above.
Daily changes in the account balance can also be retrieved.
And full details of all transactions can be obtained as a history.
I am quite happy with this functionality and I will be using it in one of my current projects. If there is sufficient interest, I will package it up and stick it on CRAN.