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.
This package contains four primary functions:
get_valid_currencies()
get_global_marketcap()
get_marketcap_ticker_all()
plot_top_currencies()
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.
The function get_global_marketcap()
fetches the USD value of global marketcap of all cryptocurrencies.
library(coinmarketcapr)
coinmarketcapr::setup()
get_global_marketcap()
#> ⚠ 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
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.
library(coinmarketcapr)
names(get_crypto_listings())
#> ⚠ 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"
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
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 with Themes
Since coinmarketcapr
’s get_crypto_listings()
returns a dataframe, it could be fit in alongside with Tidy Data pipeline.
library(coinmarketcapr)
library(dplyr)
#>
#> 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
library(ggplot2)
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
Coinmarketcapr is powered by Coinmarketcap.com https://coinmarketcap.com/api/