This vignette demos the usage of two functions from the xchangeR package:

  • eur converts a number to a string by adding the Euro sign (€), rounding up to 2 digits and using the comma as the separator.
  • eurusds looks up the daily USD/EUR exchange rate via an API call for the specified date range.

In this demo we’re going to:

  1. Fetch the daily volume of Bitcoins sold for “USDT” on Binance in the past 45 days.
  2. Calculate the prices in EUR.
  3. Report on the overall value of the asset in EUR on a ggplot.

Load the xchangeR package

Other packages used for this demo:

  • binancer
  • dplyr
  • data.table
  • ggplot2
  • scales

Fetch the daily volume of Bitcoins sold

Let’s look at the daily Bitcoin prices in USD for the past 45 days. We’re only interested in the day (open_time) and the opening price (open).

Calculate the price in EUR

At this point we have the daily prices for Bitcoin, but only in USD. In order to see the prices in EUR, we have to look up the daily exchange rates by utilizing the eurusds function and join them to btc_prices.

As we can see, there are some NA values in the exchange_rate column. The reason for this is that the exchange rates are only available from the API for weekdays. To overcome this obstacle, we have to apply a rolling join, rather than a left join.

Now we can calculate the price in EUR, and format it as such with the eur function.

Report on the overall value of the asset

As we converted the price to Euro format in the previous example, in order to visualize it, we’ll utilize the uneur function from the xchangeR package that transforms the string to a number.