Cryptor
An R wrapper for the CryptoCompare API.
Install / Use
/learn @blairj09/CryptorREADME
cryptor
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.
Installation
You can install cryptor from github with:
# install.packages("devtools")
devtools::install_github("blairj09/cryptor")
Usage
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)
Available Exchanges
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)
#> # A tibble: 6 x 3
#> exchange coin market
#> <chr> <chr> <chr>
#> 1 Cryptsy 42 BTC
#> 2 Cryptsy 42 XRP
#> 3 Cryptsy RDD LTC
#> 4 Cryptsy RDD USD
#> 5 Cryptsy RDD XRP
#> 6 Cryptsy RDD BTC
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).
Available Coins
All coins supported by the API and correspanding details can be obtained using the get_coins() function.
coins <- get_coins()
head(coins)
#> # A tibble: 6 x 16
#> id url image_url name symbol coin_name full_name algorithm
#> <int> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 4321 /coins/… /media/1231… 42 42 42 Coin 42 Coin (… Scrypt
#> 2 749869 /coins/… /media/2701… 300 300 300 token 300 token… <NA>
#> 3 33639 /coins/… /media/3520… 365 365 365Coin 365Coin (… X11
#> 4 21227 /coins/… /media/3510… 404 404 404Coin 404Coin (… Scrypt
#> 5 20909 /coins/… /media/3509… 611 611 SixEleven SixEleven… SHA256
#> 6 28223 /coins/… /media/3515… 808 808 808 808 (808) SHA256
#> # ... with 8 more variables: proof_type <chr>, fully_premined <int>,
#> # total_coin_supply <chr>, pre_mined_value <chr>,
#> # total_coins_free_float <chr>, sort_order <int>, sponsored <lgl>,
#> # is_trading <lgl>
Current Price Data
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")
#> # A tibble: 2 x 3
#> fromsymbol tosymbol price
#> <chr> <chr> <dbl>
#> 1 BTC USD 10439.
#> 2 ETH USD 861.
get_price_details(c("BTC", "ETH"), "USD")
#> # A tibble: 2 x 29
#> type market fromsymbol tosymbol flags price lastupdate
#> <int> <chr> <chr> <chr> <int> <dbl> <dttm>
#> 1 5 CCCAGG BTC USD 2 10439. 2018-03-01 04:24:46
#> 2 5 CCCAGG ETH USD 4 861. 2018-03-01 04:24:49
#> # ... with 22 more variables: lastvolume <dbl>, lastvolumeto <dbl>,
#> # lasttradeid <int>, volumeday <dbl>, volumedayto <dbl>,
#> # volume24hour <dbl>, volume24hourto <dbl>, openday <dbl>,
#> # highday <dbl>, lowday <dbl>, open24hour <dbl>, high24hour <dbl>,
#> # low24hour <dbl>, lastmarket <chr>, change24hour <dbl>,
#> # changepct24hour <dbl>, changeday <dbl>, changepctday <dbl>,
#> # supply <dbl>, mktcap <dbl>, totalvolume24h <dbl>,
#> # totalvolume24hto <dbl>
Historical Price Data
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)
#> # A tibble: 6 x 7
#> time close high low open volumefrom volumeto
#> <dttm> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2018-01-30 00:00:00 144. 169. 136. 167. 450127. 67979718.
#> 2 2018-01-31 00:00:00 146. 147. 131. 144. 266456. 37414174.
#> 3 2018-02-01 00:00:00 126. 147. 114. 146. 368930. 47844293.
#> 4 2018-02-02 00:00:00 122. 132. 94.0 126. 700073. 79912243.
#> 5 2018-02-03 00:00:00 124. 130. 107. 122. 247394. 29901510.
#> 6 2018-02-04 00:00:00 107. 125. 99.4 124. 304361. 33951028.
Snapshot Data
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)
#> [1] "page_title" "page_description"
#> [3] "base_url" "base_image_url"
#> [5] "og_image_url" "og_image_width"
#> [7] "og_image_height" "id"
#> [9] "document_type" "h1text"
#> [11] "danger_top" "warning_top"
#> [13] "info_top" "symbol"
#> [15] "url" "base_angular_url"
#> [17] "name" "image_url"
#> [19] "description" "features"
#> [21] "technology" "total_coin_supply"
#> [23] "difficulty_adjustment" "block_reward_reduction"
#> [25] "algorithm" "proof_type"
#> [27] "start_date" "twitter"
#> [29] "website_url" "website"
#> [31] "last_block_explorer_update_ts" "block_number"
#> [33] "block_time" "net_hashes_per_second"
#> [35] "total_coins_mined" "previous_total_coins_mined"
#> [37] "block_reward" "status"
#> [39] "white_paper"
get_pair_snapshot("BTC", "ETH")
#> $coin_data
#> # A tibble: 1 x 6
#> algorithm proof_type block_number net_hashes_per_second total_coins_min…
#> <chr> <chr> <int> <dbl> <int>
#> 1 SHA256 PoW 511412 21528020746. 16892625
#> # ... with 1 more variable: block_reward <dbl>
#>
#> $aggregated_data
#> # A tibble: 1 x 21
#> type market fromsymbol tosymbol flags price lastupdate
#> <int> <chr> <chr> <chr> <int> <dbl> <dttm>
#> 1 5 CCCAGG BTC ETH 4 12.5 2018-03-01 03:54:49
#> # ... with 14 more variables: lastvolume <dbl>, lastvolumeto <dbl>,
#> # lasttradeid <dbl>, volumeday <dbl>, volumedayto <dbl>,
#> # volume24hour <dbl>, volume24hourto <dbl>, openday <int>,
#> # highday <dbl>, lowday <dbl>, open24hour <dbl>, high24hour <dbl>,
#> # low24hour <dbl>, lastmarket <chr>
#>
#> $exchange_data
#> # A tibble: 2 x 15
#> type market fromsymbol tosymbol flags price lastupdate
#> <int> <chr> <chr> <chr> <int> <dbl> <dttm>
#> 1 2 Bleutrade BTC ETH 1 12.5 2018-03-01 03:54:49
#> 2 2 LocalBitcoins BTC ETH 1 12.4 2018-03-01 01:17:41
#> # ... with 8 more variables: lastvolume <dbl>, lastvolumeto <dbl>,
#> # lasttradeid <dbl>, volume24hour <dbl>, volume24hourto <dbl>,
#> # open24hour <dbl>, high24hour <dbl>, low24hour <dbl>
Social Data
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)
#> List of 6
#> $ similar_items :Classes 'tbl_df', 'tbl' and 'data.frame': 10 obs. of 6 variables:
#> ..$ id : int [1:10] 7605 5031 3808 127356 46
