Retrieves current prices of supported coins

current_price(
  coin_ids,
  vs_currencies = c("usd"),
  include_market_cap = TRUE,
  include_24h_vol = TRUE,
  include_24h_change = TRUE,
  max_attempts = 3
)

Arguments

coin_ids

(character): a vector with IDs of the coins of interest. An up-to-date list of supported coins and their IDs can be obtained with the supported_coins() function.

vs_currencies

(character): a vector with names of the reference currencies to express the price in, e.g. c("usd", "eur", "btc"). An up-to-date list of supported vs_currencies (both fiat and cryptocurrencies) can be obtained with the supported_currencies() function. If vs_currencies contains at least one unsupported currency, the call will fail with the respective error message.

include_market_cap

(boolean, defaults to TRUE): whether to return the market capitalisation information.

include_24h_vol

(boolean, defaults to TRUE): whether to return the trading volume for the last 24 hours.

include_24h_change

(boolean, defaults to TRUE): whether to return the price percentage change compared to 24 hours ago.

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

If the API call succeeds, the function returns a tibble, which by default will contain the following columns (use arguments include_market_cap, include_24h_vol and include_24h_change

to control the inclusion of the corresponding columns):

  • coin_id (character): coin IDs, ordered alphabetically;

  • price (double): coin price;

  • vs_currency (character): reference currency, in which the price of coin_id is expressed;

  • market_cap (double): current market capitalisation;

  • vol_24h (double): trading volume in the last 24 hours;

  • price_percent_change_24h (double): percentage change of the price as compared to 24 hours ago;

  • last_updated_at (POSIXct, UTC time zone): timestamp of the last price update.

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).

Details

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 no data can be retrieved (e.g. because of a misspecified query parameter), nothing (NULL) will be returned.

Examples

if (FALSE) {
r <- current_price(
  coin_ids = c("aave", "tron", "bitcoin"),
  vs_currencies = c("usd", "eur", "gbp")
)
print(r)
}