Current market data"

knitr::opts_chunk$set(
  error = TRUE,
  collapse = TRUE,
  comment = "#>"
)

Sys.sleep(60) # to avoid build errors due to API rate limit
library(geckor)

The CoinGecko API allows one to query market data on cryptocurrencies in real time. There are several functions in geckor that can be used to collect such data.

The current prices for a set of cryptocurrencies of interest can be queried with the current_price() function. The two important arguments expected by this function are coin_ids (a character vector with coin IDs; see ?supported_coins for details) and vs_currencies (a character vector with abbreviated names of reference currencies, which are used to express the coin price in; see ?supported_currencies for details). In the example below, we are requesting the current prices for Cardano, Tron, and Polkadot, expressed in USD, EUR, and GBP:

prices <- current_price(
  coin_ids = c("cardano", "tron", "polkadot"),
  vs_currencies = c("usd", "eur", "gbp")
)

prices

See ?current_price for definitions of columns in the resultant tibble.

The exchange_rate() function can be used to obtain the current exchange rates for any supported reference currency, expressed in Bitcoin. The currency argument of this function specifies the list of currencies of interest. If currency = NULL, data for all supported currencies will be returned:

all_rates <- exchange_rate(currency = NULL)
head(all_rates, 10)

some_rates <- exchange_rate(currency = c("btc", "usd", "rub"))
some_rates

The current_market() function retrieves a rich set of data points describing the current market status of the cryptocurrencies of interest. Let's collect such data for Cardano, Tron, and Polkadot:

cm <- current_market(
  coin_ids = c("cardano", "tron", "polkadot"),
  vs_currency = "usd"
)

dplyr::glimpse(cm)

See ?current_market for definitions of columns in the resultant tibble.

The coin_tickers() function allows one to query the current data on all trading pairs of a cryptocurrency from a given exchange. In the example below, we collect such data for Cardano traded at Binance:

cardano_tickers <- coin_tickers(
  coin_id = "cardano",
  exchange_id = "binance"
)

dplyr::glimpse(cardano_tickers)

See ?coin_tickers for definitions of columns in the resultant tibble.

Finally, one can use the trending_coins() function to obtain a list of top-7 trending coins in terms of their search popularity on CoinGecko:

trending_coins()


Try the geckor package in your browser

Any scripts or data that you put into this service are public.

geckor documentation built on Nov. 1, 2021, 5:07 p.m.