Getting started with Coinmarketcapr


This vignette is to help you get started with Coinmarketcapr Package that helps to extract and monitor price and market cap of Cryptocurrencies from CoinMarketCap. Simply, Coinmarketcapr is an R-binding for Coinmarketcap API that lists Price, Marketcap, Transaction Volume of many Cryptocurrencies and tokens.

Basic Functions without API-key

This package contains four primary functions:

Getting Valid Currrenices

This function get_valid_currencies() lists a character vector with all the valid currencies (ISO Codes) supported by Coinmarketcap API. These currency codes can be used in other functions like get_global_marketcap() to extract values in the given currency.

#>  [1] "AUD" "BRL" "CAD" "CHF" "CLP" "CNY" "CZK" "DKK" "EUR" "GBP" "HKD" "HUF"
#> [13] "IDR" "ILS" "INR" "JPY" "KRW" "MXN" "MYR" "NOK" "NZD" "PHP" "PKR" "PLN"
#> [25] "RUB" "SEK" "SGD" "THB" "TRY" "TWD" "ZAR" "USD"

Getting Global Marketcap

The function get_global_marketcap() fetches the USD value of global marketcap of all cryptocurrencies.

#> ⚠ The old API is used when no 'apikey' is given.
#>   total_market_cap_usd total_24h_volume_usd bitcoin_percentage_of_market_cap
#> 1          2.02011e+11          53868397517                            65.45
#>   active_currencies active_assets active_markets        last_updated
#> 1               841          1507          20660 2019-12-03 18:37:35

Extracting all Cryptocurrencies

The function get_crypto_listings() gets various useful values such as Price, Marketcap, Total Volume, 24-hour Change and much more for all the cryptocurrencies.

#> ⚠ The old API is used when no 'apikey' is given.
#>  [1] "id"                 "name"               "symbol"            
#>  [4] "rank"               "price_usd"          "price_btc"         
#>  [7] "X24h_volume_usd"    "market_cap_usd"     "available_supply"  
#> [10] "total_supply"       "max_supply"         "percent_change_1h" 
#> [13] "percent_change_24h" "percent_change_7d"  "last_updated"

Plotting Top Cryptocurrencies

The function plot_top_currencies() makes it straightforward to make a barplot of top cryptocurrencies by their rank, based on Market cap.

Plotting Top 5 Cryptocurrencies

Plotting Top 5 Cryptocurrencies

Plotting with Themes

plot_top_currencies() outputs a ggplot object hence using + operator a new ggplot2 theme can be applied. ggthemes package offers a rich set of out-of-the-box themes.

plot_top_currencies() + 
Plot with Themes

Plot with Themes

Cryptocurrencies Market - Tidy Analysis

Since coinmarketcapr’s get_crypto_listings() returns a dataframe, it could be fit in alongside with Tidy Data pipeline.

#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>     filter, lag
#> The following objects are masked from 'package:base':
#>     intersect, setdiff, setequal, union

get_crypto_listings() %>% 
        slice(1:30) %>% 
        mutate(price_usd = as.numeric(price_usd)) %>% 
        ggplot() + geom_histogram(aes(price_usd), binwidth = 100) +
        ggtitle('Cryptocurrencies Price in USD Histogram')
#> ⚠ The old API is used when no 'apikey' is given.
Cryptocurrencies Price in USD Histogram

Cryptocurrencies Price in USD Histogram


Coinmarketcapr is powered by