Notes on the arguments
- symbol: character, the symbol of interests (e.g. “BTC”)
- start: character, starting date (e.g. “2019-01-01”)
- end: character, ending date (e.g. “2020-01-01”)
- exchange: character, the exchange of reference, if NULL it will be used a mean among the exchanges.
- currency: character, the conversion currency.
- interval: character, the time interval between the observations can be: daily, hourly, minutely.
- api_key: character, the api key obtained from cyptocompare website.
Single Symbol Price
Get the current price of any cryptocurrency in any other currency that you need. If the crypto does not trade directly into the currency requested, BTC will be used for conversion. If the opposite pair trades we invert it (eg.: BTC-XMR)
allow multiple symbols (e.g.: c(“BTC”, “ETH”))
allow multiple currency (e.g.: c(“USDT”, “BUSD”))
allow multiple exchanges (e.g.: c(“Binance”, “Kraken”, “Coinbase”))
the api key is not requested.
Example: Single Symbol Price
kab = cc_symbol_price(symbol = c("BTC", "ETH"), currency = c("USDT", "BUSD"), exchange = c("Binance", "Kraken", "Coinbase"), api_key = NULL)
kab %>%
kable() %>%
kable_classic()| Time | Exchange | Symbol | USDT | BUSD |
|---|---|---|---|---|
| 2022-12-05 20:26:36 | Binance | BTC | 16911.16 | 16913.19 |
| 2022-12-05 20:26:36 | Binance | ETH | 1250.69 | 1252.14 |
| 2022-12-05 20:26:36 | Kraken | BTC | 16892.20 | NA |
| 2022-12-05 20:26:36 | Kraken | ETH | 1250.56 | NA |
| 2022-12-05 20:26:36 | Coinbase | BTC | 16915.57 | NA |
| 2022-12-05 20:26:36 | Coinbase | ETH | 1251.59 | NA |
Historical Symbol Price (OHLCV)
Get open, high, low, close, and Volume of a symbol from the daily historical data. The values are based on 00:00 GMT time.
Example: Daily Data (1)
start_date = "2022-11-01"
end_date = "2022-12-01"
kab_daily1 = cc_price_historical(symbol = "BTC", start = start_date, end = end_date, exchange = NULL, currency = "USD", interval = "daily", api_key = NULL)
kab_daily1[1:3,] %>%
kable() %>%
kable_classic()| Date | Symbol | Currency | Exchange | High | Low | Open | Volume | Close | Adj | OC | HL |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2022-11-01 | BTC | USD | global | 20684.60 | 20336.33 | 20492.56 | 48670.97 | 20480.27 | 20510.47 | -0.0005997 | 0.0171255 |
| 2022-11-02 | BTC | USD | global | 20801.56 | 20061.18 | 20480.27 | 91094.84 | 20150.33 | 20431.37 | -0.0161101 | 0.0369061 |
| 2022-11-03 | BTC | USD | global | 20385.92 | 20040.32 | 20150.33 | 54134.03 | 20207.99 | 20213.12 | 0.0028615 | 0.0172452 |
Example: Daily Data (2)
kab_daily2 = cc_price_historical(symbol = "BTC", start = start_date, end = end_date, exchange = "Binance", currency = "USDT", interval = "daily", api_key = NULL)
kab_daily2[1:3,] %>%
kable() %>%
kable_classic()| Date | Symbol | Currency | Exchange | High | Low | Open | Volume | Close | Adj | OC | HL |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2022-11-01 | BTC | USDT | Binance | 20700.00 | 20330.74 | 20490.74 | 279955.5 | 20483.62 | 20515.37 | -0.0003475 | 0.0181626 |
| 2022-11-02 | BTC | USDT | Binance | 20800.00 | 20048.04 | 20483.62 | 373746.1 | 20151.84 | 20424.02 | -0.0161973 | 0.0375079 |
| 2022-11-03 | BTC | USDT | Binance | 20393.32 | 20031.24 | 20151.84 | 319185.2 | 20207.82 | 20212.28 | 0.0027779 | 0.0180758 |
Example: Hourly Data (1)
kab_hourly = cc_price_historical(symbol = "BTC", start = start_date, end = end_date, exchange = NULL, currency = "USD", interval = "hourly", api_key = NULL)
kab_hourly[1:3,] %>%
kable() %>%
kable_classic()| Date | Symbol | Currency | Exchange | High | Low | Open | Volume | Close | Adj | OC | HL |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2022-11-01 00:00:00 | BTC | USD | global | 20518.43 | 20464.79 | 20477.83 | 2252.25 | 20492.56 | 20491.61 | 0.0007193 | 0.0026211 |
| 2022-11-01 01:00:00 | BTC | USD | global | 20500.60 | 20442.88 | 20492.56 | 1684.15 | 20452.97 | 20471.74 | -0.0019319 | 0.0028235 |
| 2022-11-01 02:00:00 | BTC | USD | global | 20547.30 | 20452.83 | 20452.97 | 1746.89 | 20509.26 | 20500.06 | 0.0027522 | 0.0046189 |
Example: Minutely Data (1)
- with a NULL api_key or with an api_key with the free plan the maximum days are 7.
kab_minutely = cc_price_historical(symbol = "BTC", start = start_date, end = end_date, exchange = NULL, currency = "USD", interval = "minutely", api_key = NULL)
kab_minutely[1:3,] %>%
kable() %>%
kable_classic()| Date | Symbol | Currency | Exchange | High | Low | Open | Volume | Close | Adj | OC | HL |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 2022-11-29 03:27:00 | BTC | USD | global | 16276.61 | 16270.84 | 16271.85 | 23.59 | 16274.12 | 16273.73 | 0.0001395 | 0.0003546 |
| 2022-11-29 03:28:00 | BTC | USD | global | 16274.73 | 16270.39 | 16274.12 | 20.06 | 16271.13 | 16272.56 | -0.0001837 | 0.0002667 |
| 2022-11-29 03:29:00 | BTC | USD | global | 16277.37 | 16270.39 | 16271.13 | 63.08 | 16276.68 | 16273.88 | 0.0003411 | 0.0004290 |
Plot Candlestick Data
BTC = cc_price_historical(symbol = "BTC", start = "2022-11-30", end = Sys.time(), exchange = "Binance",
currency = "USDT", interval = "minutely", api_key = NULL)
BTC %>%
gg_candle(tstart = Sys.time() - 10000, tend = Sys.time(), smooth = 0.5)+
xlab("Time")+
ylab("Price")+
ggtitle("BINANCE:BTCUSDT")+
scale_x_datetime(breaks = seq(Sys.time() - 10000, Sys.time(), 2000))