knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
cryptor
provides a basic wrapper around the public API provided by CryptoCompare. CryptoCompare has provided a very comprehensive public cryptocurrency API. This package strives to create a clean and intuitive R interface for that API.
You can install cryptor
from github with:
# install.packages("devtools") devtools::install_github("blairj09/cryptor")
This package comes with several functions that map directly to CryptoCompare API endpoints. These functions center on price and other coin details for various cryptorcurrencies. CryptoCompare integrates with several exchanges and the exchange to be queried can often be requested. However, the default exchange of CCCAGG often works the best. The following outlines common use cases for various functions.
library(cryptor)
Possible exchanges to query can be requested using the get_exchanges()
function. This returns a comprehensive tibble of available exchanges along with each market available on that exchange.
exchanges <- get_exchanges() head(exchanges)
In this case, the exchange
column contains the name of the exchange while the coin
column contains the coin and the market
column contains the market supported for coin
on a given exchange
. All possible exchanges can be identified by running unique(get_exchanges()$exchage)
.
All coins supported by the API and correspanding details can be obtained using the get_coins()
function.
coins <- get_coins() head(coins)
There are two main functions for retreiving current price data. get_price()
simply returns the price of the requested coins. get_price_details()
returns current price data along with open, close, and other 24 hour price statistics. Price functions take two main parameters: fsym(s)
and tsym(s)
. These parameters specify the requested coin(s) (fsym(s)
) and the currency the price is reported in (tsym(s)
). The following examples illustrate getting price data for Bitcoin (BTC) and Etherium (ETH) in terms of US Dollars (USD).
get_price(c("BTC", "ETH"), "USD")
get_price_details(c("BTC", "ETH"), "USD")
Historical price data can be retreived using get_historical_price()
. Price can be obtained at the daily, hourly, or minute level. Minute level data is only available for the past 7 days. Anything beyond 7 days must be either daily or hourly data. The following example demonstrates how to get NEO to USD data for the past 7 days.
As a note, it seems that the API sometimes returns all historical entries, regardless of the limit provided.
btc_price_history <- get_historical_price("NEO", "USD") head(btc_price_history)
CrytpoCompare provides endpoints for "snapshot data". These endpoints provide summarized data about individual coins and coin pairs.
btc_snapshot <- get_coin_snapshot(1182) names(btc_snapshot)
get_pair_snapshot("BTC", "ETH")
One of the most impressive features of the CryptoCompare API is the ability to query some basic social stats for a given coin. The data provided contains details about the coin's github repositories, page view data from CryptoCompare's main website, and a listing of similar coins. This data can be accessed as follows:
# Social stats for Bitcoin eth_social_stats <- get_social(1182) str(eth_social_stats)
Details about top cryptocurrency pairs (by volume) can be retrived using get_top_pairs()
.
# Top ETH pairs get_top_pairs("ETH")
The API has hour, minute, and second call rate limits. These limits, along with calls made against the limit, can be retrieved using get_api_limit()
as follows:
# Second limit get_api_limit("second") # Minute limit get_api_limit("minute") # Hour limit get_api_limit("hour")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.