-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME.Rmd
144 lines (104 loc) · 5.12 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# cryptowatchR
<!-- badges: start -->
[](https://cran.r-project.org/package=cryptowatchR)
[](https://www.repostatus.org/#active)
[](https://lifecycle.r-lib.org/articles/stages.html#stable-1)
[](https://github.com/lorenzbr/cryptowatchR/actions)
[](https://codecov.io/gh/lorenzbr/cryptowatchR?branch=main)
<!-- badges: end -->
An API wrapper for Cryptowatch written in R
## Introduction
This R package provides a wrapper for the Cryptowatch API. You can get prices and other information (volume, trades, order books, bid and ask prices, live quotes, and more) about cryptocurrencies and crypto exchanges. Check [https://docs.cryptowat.ch/rest-api](https://docs.cryptowat.ch/rest-api) for a detailed documentation. The API is free of charge and does not require you to create an API key. For example, you can easily retrieve historical prices for a large number of cryptocurrencies without setting up an account. However, for heavy users, this option is included in the package as well.
## Installation
You can install the released version of cryptowatchR from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("cryptowatchR")
```
You can install the development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("lorenzbr/cryptowatchR")
```
## Usage
```r
## Examples
library(cryptowatchR)
# Some settings
exchange <- "kraken"
pair <- "btcusd"
# Daily prices of Bitcoin in USD
df_ohlc_daily <- get_ohlc(pair)
# Hourly prices
df_ohlc_hourly <- get_ohlc(pair, periods = 3600,
before = as.numeric(as.POSIXct(Sys.Date())),
after = as.numeric(as.POSIXct(Sys.Date() - 5)),
exchange, datetime = FALSE)
# Hourly prices using date/datetime variables
df_ohlc_hourly_datetime <- get_ohlc(pair, periods = 3600,
before = Sys.Date(),
after = Sys.Date() - 5,
exchange, datetime = TRUE)
# Daily prices using date/datetime variables
df_ohlc_daily_datetime <- get_ohlc(pair, periods = 86400,
before = "2021-05-12",
after = "2021-01-01",
exchange, datetime = TRUE)
# Daily prices using POSIX time
df_ohlc_daily_posix <- get_ohlc(pair, periods = 86400,
before = as.numeric(as.POSIXct("2021-05-12 14:00:00 UCT")),
after = as.numeric(as.POSIXct("2021-01-01 14:00:00 UCT")),
exchange, datetime = FALSE)
# Current market price
current_price <- get_current_price("btcusd")
current_prices <- get_current_price()
## Get trades
# Most recent trades (default is 50)
trades <- get_trades(pair)
# 100 trades
trades_100 <- get_trades(pair, limit = 100, datetime = FALSE)
# 200 trades (maximum is 1000) since 1589571417 (unix timestamp)
trades_unix <- get_trades(pair, since = 1589571417, limit = 200, datetime = FALSE)
# 1000 trades and datetime is TRUE
trades_datetime <- get_trades(pair, since = "2021-06-01", limit = 1000)
# 24h-hour summary of cryptocurrency pairs
summary <- get_summary("btcusd")
summaries <- get_summary()
summaries_id <- get_summary(keyBy = "id")
summaries_symbols <- get_summary(keyBy = "symbols")
# Orderbook for Bitcoin-USD (bid and ask with Price and Amount)
orderbook <- get_orderbook(pair, exchange = exchange)
orderbook_depth <- get_orderbook(pair, exchange = exchange, depth = 100)
orderbook_span <- get_orderbook(pair, exchange = exchange, span = 0.5)
orderbook_limit <- get_orderbook(pair, exchange = exchange, limit = 1)
# Get liquidity sums in the order book of Bitcoin in USD
liquidity <- get_orderbook_liquidity("btcusd")
# Live quote for 50 Bitcoins
calculator <- get_orderbook_calculator("btcusd", amount = 50)
# Asset information
df_assets <- get_assets()
asset_btc <- get_assets("btc")
# Information on pairs of currencies
df_pairs <- get_pairs()
pair_btcusd <- get_pairs("btcusd")
# Information on crypto exchanges
df_exchanges <- get_exchanges()
exchange_kraken <- get_exchanges("kraken")
```
## Contact
Please submit bug reports and suggestions via <https://github.com/lorenzbr/cryptowatchR/issues>
## License
This R package is licensed under the GNU General Public License v3.0.
See [here](https://github.com/lorenzbr/cryptowatchR/blob/main/LICENSE.md) for further information.