Site icon R-bloggers

How to get Cryptocurrency prices in R

[This article was first published on R – Predictive Hacks, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Today, we will show how you can easily get the Cryptocurrency Prices using R. We will work with the crypto package.

You can install the crypto package from GitHub:

# Installing via Github
devtools::install_github("jessevent/crypto")
 


How to get the list of the Cryptocurrencies

library(crypto)
library(tidyverse)
list_coins<-crypto_list()

# Print 10 of them
list_coins%>%head(10)%>%select(symbol, name)
 

   symbol name             
 1 BTC    Bitcoin     
 2 ETH    Ethereum    
 3 XRP    XRP         
 4 USDT   Tether      
 5 BCH    Bitcoin Cash
 6 BSV    Bitcoin SV  
 7 LTC    Litecoin    
 8 ADA    Cardano     
 9 LINK   Chainlink   
10 BNB    Binance Coin
 


How to get the Cryptocurrency Prices


Let’s say that I am interested in BTC, XRP, BCH and LTC and I want to get their daily values from 2020-01-01 onwards.

btc<-crypto_history(coin = 'BTC', start_date = "20200101")
xrp<-crypto_history(coin = 'XRP', start_date = "20200101")
bch<-crypto_history(coin = 'BCH', start_date = "20200101")
ltc<-crypto_history(coin = 'LTC', start_date = "20200101")

df<-rbind(btc,xrp,bch,ltc)

df%>%head()
slugsymbolnamedateranknowopenhighlowclosevolumemarketclose_ratiospread
bitcoinBTCBitcoin1/1/202017194.897254.337174.947200.17185656649971.306E+110.3177982179.39
bitcoinBTCBitcoin1/2/202017202.557212.166935.276985.47208020834651.267E+110.18129943276.89
bitcoinBTCBitcoin1/3/202016984.437413.7269157344.88281114810321.332E+110.86196663498.72
bitcoinBTCBitcoin1/4/202017345.387427.397309.517410.66184442712751.344E+110.85807601117.88
bitcoinBTCBitcoin1/5/202017410.457544.57400.547411.32197250740951.345E+110.07488191143.96
bitcoinBTCBitcoin1/6/202017410.457781.877409.297769.22232762615981.41E+110.96604756372.58

To leave a comment for the author, please follow the link and comment on their blog: R – Predictive Hacks.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.