Learn R Programming

geckor (version 0.2.0)

exchange_rate: Exchange rate

Description

Retrieves the current exchange rate for a crypto- of fiat currency in Bitcoin

Usage

exchange_rate(currency = NULL, max_attempts = 3)

Arguments

currency

(character or NULL): a vector with abbreviated names of the currencies of interest. An up-to-date list of supported currencies (both fiat and cryptocurrencies) can be retrieved with the supported_currencies() function. If an unsupported currency is requested, the call will fail with the respective error message. If currency = NULL (default), the function will return exchange rates for all supported currencies.

max_attempts

(double, positive): specifies the maximum number of attempts to call the CoinGecko API (e.g., if the first call fails for some reason). Additional attempts are implemented with an exponential backoff. Defaults to 3.

Value

A tibble with the following columns:

  • timestamp (POSIXct): date and time of the API request;

  • currency (character): abbreviated name of the currency;

  • name (character): common name of the currency;

  • price_in_btc (double): price in Bitcoin;

  • type (character): type of the currency ("fiat" or "crypto").

Details

This function is based on the public CoinGecko API, which has a limit of 50 calls per minute. Please keep this limit in mind when developing your applications.

Examples

Run this code
# NOT RUN {
# get exchange rates for all supported currencies
r1 <- exchange_rate()
print(r1)

# get exchange rates for a set of currencies:
r2 <- exchange_rate(currency = c("usd", "eur", "gbp"))
print(r2)
# }

Run the code above in your browser using DataLab