View source: R/exchange_rate.R
exchange_rate | R Documentation |
Retrieves the current exchange rate for a crypto- of fiat currency in Bitcoin
exchange_rate(currency = NULL, max_attempts = 3)
currency |
(character or |
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. |
This function is based on the public CoinGecko API, which has a rate limit of 10-30 calls per minute. Please keep this limit in mind when developing your applications.
If the API call succeeds, the function returns 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"
).
If no data can be retrieved (e.g., because of going over the API
rate limit or mis-specifying the query parameters), the function
returns nothing (NULL
).
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.