library(geckor)
#> R client for the CoinGecko API
#> Developed by Next Game Solutions (http://nextgamesolutions.com)
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 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:
<- current_price(
prices coin_ids = c("cardano", "tron", "polkadot"),
vs_currencies = c("usd", "eur", "gbp")
)
prices#> # A tibble: 9 x 7
#> coin_id price vs_currency market_cap vol_24h price_percent_change_24h
#> <chr> <dbl> <chr> <dbl> <dbl> <dbl>
#> 1 cardano 1.34 usd 42991971878. 1052770019. -0.126
#> 2 cardano 1.13 eur 36263943239. 888016775. 0.0571
#> 3 cardano 0.967 gbp 31043170142. 760172595. 0.259
#> 4 polkadot 15.2 usd 15346431833. 391467103. -1.73
#> 5 polkadot 12.8 eur 12944791983. 330204459. -1.55
#> 6 polkadot 11.0 gbp 11081182687. 282666260. -1.35
#> 7 tron 0.0615 usd 4412364419. 751789173. -0.311
#> 8 tron 0.0519 eur 3722177964. 634137926. -0.129
#> 9 tron 0.0444 gbp 3185771234. 542843656. 0.0730
#> # ... with 1 more variable: last_updated_at <dttm>
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:
<- exchange_rate(currency = NULL)
all_rates head(all_rates, 10)
#> # A tibble: 10 x 5
#> timestamp currency name price_in_btc type
#> <dttm> <chr> <chr> <dbl> <chr>
#> 1 2021-07-12 13:37:47 aed United Arab Emirates Dirham 123483. fiat
#> 2 2021-07-12 13:37:47 ars Argentine Peso 3224280. fiat
#> 3 2021-07-12 13:37:47 aud Australian Dollar 45048. fiat
#> 4 2021-07-12 13:37:47 bch Bitcoin Cash 68.8 crypto
#> 5 2021-07-12 13:37:47 bdt Bangladeshi Taka 2849855. fiat
#> 6 2021-07-12 13:37:47 bhd Bahraini Dinar 12672. fiat
#> 7 2021-07-12 13:37:47 bits Bits 1000000 crypto
#> 8 2021-07-12 13:37:47 bmd Bermudian Dollar 33617. fiat
#> 9 2021-07-12 13:37:47 bnb Binance Coin 104. crypto
#> 10 2021-07-12 13:37:47 brl Brazil Real 176864. fiat
<- exchange_rate(currency = c("btc", "usd", "rub"))
some_rates
some_rates#> # A tibble: 3 x 5
#> timestamp currency name price_in_btc type
#> <dttm> <chr> <chr> <dbl> <chr>
#> 1 2021-07-12 13:37:48 btc Bitcoin 1 crypto
#> 2 2021-07-12 13:37:48 rub Russian Ruble 2508050. fiat
#> 3 2021-07-12 13:37:48 usd US Dollar 33617. fiat
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:
<- current_market(
cm coin_ids = c("cardano", "tron", "polkadot"),
vs_currency = "usd"
)
::glimpse(cm)
dplyr#> Rows: 3
#> Columns: 32
#> $ coin_id <chr> "cardano", "polkadot", "tron"
#> $ symbol <chr> "ada", "dot", "trx"
#> $ name <chr> "Cardano", "Polkadot", "TRON"
#> $ vs_currency <chr> "usd", "usd", "usd"
#> $ last_updated_at <dttm> 2021-07-12 12:37:44, 2021-07-~
#> $ current_price <dbl> 1.340000, 15.200000, 0.061487
#> $ market_cap <dbl> 42991971878, 15346431833, 441~
#> $ market_cap_rank <int> 5, 9, 25
#> $ fully_diluted_valuation <dbl> 60332288548, NA, NA
#> $ total_volume <int> 1052770019, 391467103, 751789~
#> $ high_24h <dbl> 1.380000, 15.860000, 0.063296
#> $ low_24h <dbl> 1.340000, 15.150000, 0.061313
#> $ price_change_24h <dbl> -0.001685956, -0.266882944, -~
#> $ price_change_percentage_24h <dbl> -0.12573, -1.72590, -0.31144
#> $ market_cap_change_24h <dbl> -5634753, -231134636, -10257~
#> $ market_cap_change_percentage_24h <dbl> -0.01310, -1.48377, -0.23193
#> $ circulating_supply <dbl> 32066390668, 1009417005, 7166~
#> $ total_supply <dbl> 45000000000, 1090366138, 1008~
#> $ max_supply <dbl> 4.5e+10, NA, NA
#> $ ath <dbl> 2.450000, 49.350000, 0.231673
#> $ ath_change_percentage <dbl> -45.27688, -69.16504, -73.455~
#> $ ath_date <dttm> 2021-05-16 07:44:28, 2021-05-~
#> $ atl <dbl> 0.01925275, 2.70000000, 0.001~
#> $ atl_change_percentage <dbl> 6850.9177, 464.1146, 3308.3008
#> $ atl_date <dttm> 2020-03-13 02:22:55, 2020-08-~
#> $ price_change_percentage_1h_in_currency <dbl> -0.4281492, -0.1358553, -0.13~
#> $ price_change_percentage_24h_in_currency <dbl> -0.1257338, -1.7259015, -0.31~
#> $ price_change_percentage_7d_in_currency <dbl> -8.064827, -5.198131, -8.8652~
#> $ price_change_percentage_14d_in_currency <dbl> -0.2470793, 1.4718580, -5.333~
#> $ price_change_percentage_30d_in_currency <dbl> -6.826321, -27.829919, -11.24~
#> $ price_change_percentage_200d_in_currency <dbl> 867.4255, 220.6740, 145.9176
#> $ price_change_percentage_1y_in_currency <dbl> 967.7327, NA, 234.9683
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:
<- coin_tickers(
cardano_tickers coin_id = "cardano",
exchange_id = "binance"
)
::glimpse(cardano_tickers)
dplyr#> Rows: 14
#> Columns: 23
#> $ exchange_id <chr> "binance", "binance", "binance", "binan~
#> $ exchange_name <chr> "Binance", "Binance", "Binance", "Binan~
#> $ coin_id <chr> "cardano", "cardano", "cardano", "carda~
#> $ name <chr> "Cardano", "Cardano", "Cardano", "Carda~
#> $ base <chr> "ADA", "ADA", "ADA", "ADA", "ADA", "ADA~
#> $ target <chr> "USDT", "BUSD", "BTC", "ETH", "EUR", "B~
#> $ trust_score <chr> "green", "green", "green", "green", "gr~
#> $ last_price <dbl> 1.3402e+00, 1.3351e+00, 3.9860e-05, 6.3~
#> $ last_fetch_at <dttm> 2021-07-12 12:21:00, 2021-07-12 12:28:~
#> $ last_traded_at <dttm> 2021-07-12 12:21:00, 2021-07-12 12:28:~
#> $ bid_ask_spread_percentage <dbl> 0.017380, 0.037249, 0.025088, 0.099053,~
#> $ trading_volume_24h <dbl> 92791442.1, 17822171.7, 33707044.3, 379~
#> $ last_price_btc <dbl> 3.992e-05, 3.974e-05, 3.986e-05, 3.981e~
#> $ last_price_eth <dbl> 0.00063716, 0.00063387, 0.00063582, 0.0~
#> $ last_price_usd <dbl> 1.34, 1.34, 1.34, 1.34, 1.34, 1.34, 1.3~
#> $ trading_volume_24h_btc <dbl> 3705.000000, 708.211000, 1344.000000, 1~
#> $ trading_volume_24h_eth <dbl> 59123.000, 11297.000, 21432.000, 2412.0~
#> $ trading_volume_24h_usd <int> 124653217, 23823162, 45195420, 5083973,~
#> $ cost_to_move_up_2percent_usd <dbl> 3526168.46, 1007708.58, 932586.55, 6454~
#> $ cost_to_move_down_2percent_usd <dbl> 3030312.92, 1292716.74, 812390.51, 5491~
#> $ is_anomaly <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALS~
#> $ is_stale <lgl> FALSE, FALSE, FALSE, FALSE, FALSE, FALS~
#> $ trade_url <chr> "https://www.binance.com/en/trade/ADA_U~
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()
#> # A tibble: 7 x 7
#> timestamp popularity_rank_~ coin_id name symbol market_cap_rank
#> <dttm> <int> <chr> <chr> <chr> <int>
#> 1 2021-07-12 13:37:49 1 axie-inf~ Axie I~ AXS 81
#> 2 2021-07-12 13:37:49 2 kucoin-s~ KuCoin~ KCS 77
#> 3 2021-07-12 13:37:49 3 smooth-l~ Smooth~ SLP 230
#> 4 2021-07-12 13:37:49 4 illuvium Illuvi~ ILV 338
#> 5 2021-07-12 13:37:49 5 shiba-inu Shiba ~ SHIB 29
#> 6 2021-07-12 13:37:49 6 my-defi-~ My DeF~ DPET 625
#> 7 2021-07-12 13:37:49 7 constell~ Conste~ DAG 121
#> # ... with 1 more variable: price_btc <dbl>