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.

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%);

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.