Current market data

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 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
#> # 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   2      usd         63542311560. 2003905200.                     2.31
#> 2 cardano   1.73   eur         54907102046. 1732065440.                     2.18
#> 3 cardano   1.46   gbp         46524282593. 1466800493.                     2.49
#> 4 polkadot 44.3    usd         45677466802. 1324266979.                     5.92
#> 5 polkadot 38.3    eur         39485201015. 1144623542.                     5.77
#> 6 polkadot 32.4    gbp         33436545184.  969325025.                     6.10
#> 7 tron      0.102  usd          7235134893. 2252996359.                     1.19
#> 8 tron      0.0881 eur          6251901766. 1947366138.                     1.05
#> 9 tron      0.0746 gbp          5297406596. 1649127998.                     1.36
#> # ... 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:

all_rates <- exchange_rate(currency = NULL)
head(all_rates, 10)
#> # A tibble: 10 x 5
#>    timestamp           currency name                        price_in_btc type  
#>    <dttm>              <chr>    <chr>                              <dbl> <chr> 
#>  1 2021-11-01 09:49:51 aed      United Arab Emirates Dirham      228339. fiat  
#>  2 2021-11-01 09:49:51 ars      Argentine Peso                  6197280. fiat  
#>  3 2021-11-01 09:49:51 aud      Australian Dollar                 82814. fiat  
#>  4 2021-11-01 09:49:51 bch      Bitcoin Cash                        105. crypto
#>  5 2021-11-01 09:49:51 bdt      Bangladeshi Taka                5368581. fiat  
#>  6 2021-11-01 09:49:51 bhd      Bahraini Dinar                    23438. fiat  
#>  7 2021-11-01 09:49:51 bits     Bits                            1000000  crypto
#>  8 2021-11-01 09:49:51 bmd      Bermudian Dollar                  62168. fiat  
#>  9 2021-11-01 09:49:51 bnb      Binance Coin                        117. crypto
#> 10 2021-11-01 09:49:51 brl      Brazil Real                      350489. fiat

some_rates <- exchange_rate(currency = c("btc", "usd", "rub"))
some_rates
#> # A tibble: 3 x 5
#>   timestamp           currency name          price_in_btc type  
#>   <dttm>              <chr>    <chr>                <dbl> <chr> 
#> 1 2021-11-01 09:49:51 btc      Bitcoin                 1  crypto
#> 2 2021-11-01 09:49:51 rub      Russian Ruble     4398435. fiat  
#> 3 2021-11-01 09:49:51 usd      US Dollar           62168. 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:

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

dplyr::glimpse(cm)
#> 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-11-01 09:49:28, 2021-11-~
#> $ current_price                            <dbl> 2.000000, 44.330000, 0.101936
#> $ market_cap                               <dbl> 63542311560, 45677466802, 723~
#> $ market_cap_rank                          <int> 5, 8, 30
#> $ fully_diluted_valuation                  <dbl> 89171371039, NA, NA
#> $ total_volume                             <dbl> 2003905200, 1324266979, 22529~
#> $ high_24h                                 <dbl> 2.000000, 44.460000, 0.102011
#> $ low_24h                                  <dbl> 1.92000, 41.33000, 0.09815
#> $ price_change_24h                         <dbl> 0.04525739, 2.48000000, 0.001~
#> $ price_change_percentage_24h              <dbl> 2.31414, 5.91567, 1.18962
#> $ market_cap_change_24h                    <dbl> 628750748, 2106541495, -5246~
#> $ market_cap_change_percentage_24h         <dbl> 0.99939, 4.83474, -0.07246
#> $ circulating_supply                       <dbl> 32066390668, 1046004149, 7166~
#> $ total_supply                             <dbl> 45000000000, 1126954665, 1008~
#> $ max_supply                               <dbl> 4.5e+10, NA, NA
#> $ ath                                      <dbl> 3.090000, 49.350000, 0.231673
#> $ ath_change_percentage                    <dbl> -35.11797, -10.28816, -56.097~
#> $ ath_date                                 <dttm> 2021-09-02 06:00:10, 2021-05-~
#> $ atl                                      <dbl> 0.01925275, 2.70000000, 0.001~
#> $ atl_change_percentage                    <dbl> 10302.933, 1541.246, 5536.967
#> $ atl_date                                 <dttm> 2020-03-13 02:22:55, 2020-08-~
#> $ price_change_percentage_1h_in_currency   <dbl> 1.212416, 1.598759, 1.024652
#> $ price_change_percentage_24h_in_currency  <dbl> 2.314139, 5.915670, 1.189617
#> $ price_change_percentage_7d_in_currency   <dbl> -5.994873, 4.252299, 2.277023
#> $ price_change_percentage_14d_in_currency  <dbl> -7.270068, 5.226417, 3.095765
#> $ price_change_percentage_30d_in_currency  <dbl> -10.941119, 38.628612, 7.5294~
#> $ price_change_percentage_200d_in_currency <dbl> 37.417789, 4.315348, -27.8561~
#> $ price_change_percentage_1y_in_currency   <dbl> 2054.5777, 961.0734, 294.2327

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)
#> 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", "BTC", "USDC", "EUR", "ETH", "T~
#> $ trust_score                    <chr> "green", "green", "green", "green", "gr~
#> $ last_price                     <dbl> 2.0010e+00, 3.2210e-05, 1.9990e+00, 1.7~
#> $ last_fetch_at                  <dttm> 2021-11-01 09:35:33, 2021-11-01 09:36:~
#> $ last_traded_at                 <dttm> 2021-11-01 09:35:33, 2021-11-01 09:36:~
#> $ bid_ask_spread_percentage      <dbl> 0.050659, 0.031172, 0.100756, 0.058275,~
#> $ trading_volume_24h             <dbl> 145934666.5, 35074897.2, 2012438.9, 513~
#> $ last_price_btc                 <dbl> 3.224e-05, 3.221e-05, 3.220e-05, 3.225e~
#> $ last_price_eth                 <dbl> 0.00046217, 0.00046170, 0.00046152, 0.0~
#> $ last_price_usd                 <dbl> 2.00, 2.00, 2.00, 2.00, 2.00, 1.99, 2.0~
#> $ trading_volume_24h_btc         <dbl> 4705.000000, 1130.000000, 64.807000, 16~
#> $ trading_volume_24h_eth         <dbl> 67447.00000, 16194.00000, 928.78300, 23~
#> $ trading_volume_24h_usd         <int> 292236992, 70188027, 4026249, 10296358,~
#> $ cost_to_move_up_2percent_usd   <dbl> 5192544.77, 835390.95, 600475.96, 24128~
#> $ cost_to_move_down_2percent_usd <dbl> 2125641.25, 809426.57, 198268.53, 29561~
#> $ 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-11-01 09:49:54                 1 ariva     Ariva   ARV                674
#> 2 2021-11-01 09:49:54                 2 taboo-to~ Taboo ~ TABOO              304
#> 3 2021-11-01 09:49:54                 3 richquack Rich Q~ QUACK              687
#> 4 2021-11-01 09:49:54                 4 wagyuswap WagyuS~ WAG                711
#> 5 2021-11-01 09:49:54                 5 shiba-inu Shiba ~ SHIB                 9
#> 6 2021-11-01 09:49:54                 6 unilayer  UniLay~ LAYER              899
#> 7 2021-11-01 09:49:54                 7 decentra~ Decent~ MANA                55
#> # ... with 1 more variable: price_btc <dbl>