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
)
(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.
(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.
(boolean, defaults to
TRUE
): whether to return the market capitalisation information.
(boolean, defaults to TRUE
):
whether to return the trading volume for the last 24 hours.
(boolean, defaults to
TRUE
): whether to return the price percentage change compared to 24
hours ago.
(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.
A tibble, which by the 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.
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.
If no data can be retrieved (e.g. because of a misspecified
query parameter), nothing (NULL
) will be returned.
# NOT RUN {
r <- current_price(
coin_ids = c("aave", "tron", "bitcoin"),
vs_currencies = c("usd", "eur", "gbp")
)
print(r)
# }
Run the code above in your browser using DataLab