Skip to content

Commit

Permalink
Updated Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
serkor1 committed Oct 6, 2023
1 parent a0e00ce commit cc152a6
Show file tree
Hide file tree
Showing 17 changed files with 387 additions and 177 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Imports:
curl (>= 5.0.2),
httr (>= 1.4.7),
jsonlite (>= 1.8.7),
magrittr,
plotly,
rlang (>= 1.1.1),
xts (>= 0.13.1),
zoo (>= 1.8-12)
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(availableExchanges)
export(availableIntervals)
export(availableTickers)
export(chart)
export(getQuote)
importFrom(curl,has_internet)
importFrom(httr,GET)
importFrom(httr,content)
importFrom(jsonlite,fromJSON)
importFrom(magrittr,"%>%")
importFrom(plotly,layout)
importFrom(plotly,plot_ly)
importFrom(plotly,subplot)
importFrom(rlang,abort)
importFrom(rlang,trace_back)
importFrom(xts,as.xts)
Expand Down
2 changes: 1 addition & 1 deletion R/availableIntervals.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' See all available intervals for the futures and spot markets
#' on the desired exchange.
#' on the desired exchange
#'
#' This function shows all
#' available intervals available
Expand Down
124 changes: 124 additions & 0 deletions R/chart.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# script: scr_chart
# date: 2023-10-06
# author: Serkan Korkmaz, [email protected]
# objective: Chart the quotes using
# plotly
# script start;

#' Create a candlestick chart
#' with volume and bollinger bands
#'
#' This function returns a plotly candlestick with
#' the most common indicators.
#'
#'
#' @export

chart <- function(
quote,
deficiency = FALSE,
slider = TRUE
) {

# 1) convert quote
# to data.frame
quote_ <- as.data.frame(
quote
)

# 2) determine
# wether it closed
# above or below
quote_$direction <- ifelse(
quote_$Close > quote_$Open,
yes = 'Increasing',
no = 'Decreasing'
)

# 2) Create candlestick
candlestick <- plotly::plot_ly(
data = quote_,
name = 'Price',
x = rownames(quote_),
type = 'candlestick',
open = ~Open,
close = ~Close,
high = ~High,
low = ~Low,
increasing = list(
line =list(color =ifelse(
test = deficiency,
yes = '#FFD700',
no = 'palegreen'
)
)
),
decreasing = list(
line =list(color =ifelse(
test = deficiency,
yes = '#0000ff',
no = 'tomato'
)
)
)
)

# 3) create volume
# plot
volume <- plotly::plot_ly(
data = quote_,
name = 'Volume',
x = rownames(quote_),
y = ~Volume,
type = 'bar',
color = ~direction,
colors = c(
ifelse(
test = deficiency,
yes = '#FFD700',
no = 'tomato'
),
ifelse(
test = deficiency,
yes = '#0000ff',
no = 'palegreen'
)
)
)



# 4) generate plot
plot <- plotly::subplot(
candlestick,
volume,
heights = c(0.7,0.2),
nrows=2,
shareX = TRUE,
titleY = TRUE
)

plot %>% plotly::layout(
title = "Basic Candlestick Chart",
xaxis = list(rangeslider = list(visible = slider)),
showlegend = FALSE,
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)'
)


}



# chart(
# subset(
# ATOMUSDT,
# ATOMUSDT$exchange == 1 & ATOMUSDT$market == 1
# ),
# deficiency = FALSE
# )



# script end;
3 changes: 3 additions & 0 deletions R/cryptoQuotes-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
#' @importFrom httr content
#' @importFrom httr GET
#' @importFrom jsonlite fromJSON
#' @importFrom plotly layout
#' @importFrom plotly plot_ly
#' @importFrom plotly subplot
#' @importFrom rlang abort
#' @importFrom rlang trace_back
#' @importFrom xts as.xts
Expand Down
2 changes: 1 addition & 1 deletion R/getQuote.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Get a quote on a cryptopair from one
#' of the major exchanges.
#' of the major exchanges
#'
#' This function returns a crypto quote from
#' one of the available exchanges. The function supports
Expand Down
14 changes: 14 additions & 0 deletions R/utils-pipe.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
#' @param lhs A value or the magrittr placeholder.
#' @param rhs A function call using the magrittr semantics.
#' @return The result of calling `rhs(lhs)`.
NULL
50 changes: 16 additions & 34 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,35 @@ Currently, cryptoQuotes supports perpetual futures and spot markets on the follo
> **Note:** cryptoQuotes supports various intervals limited
> to what the different exchange APIs allows. The lowest interval is 1s (Seconds), and the highest is 1M (Months)
#### Basic usage

Get USDT denominated ATOM in the spot market from Binance in `30m` intervals,

```{r example}
## get perpetual contracts on USDT denominated ATOM
spotPrice <- cryptoQuotes::getQuote(
ticker = 'ATOMUSDT',
source = 'binance',
futures = FALSE,
interval = '30m'
)
```

This `spotPrice` can be passed to the `chartSeries` from `quantmod` directly to chart it with candlesticks.

```{r chartSeries, echo=TRUE, warning=FALSE, message = FALSE}
## chart the spotPrice series
## using quantmod
quantmod::chartSeries(
x = spotPrice,
theme = quantmod::chartTheme('black')
)
```

When the `spotPrice` has been charted, the indicators in `quantmod` is directly applicable. See for example `addBBands`

```{r addBBands, echo=TRUE, warning=FALSE, message = FALSE}
## add bollinger bands
## using quantmod
quantmod::addBBands()
```

#### Installation

**Stable Version**
``` r
```{r, eval = FALSE}
devtools::install_github(
repo = 'https://github.com/serkor1/cryptoQuotes/',
ref = 'main'
)
```

**Development Version**
``` r
```{r, eval = FALSE}
devtools::install_github(
repo = 'https://github.com/serkor1/cryptoQuotes/',
ref = 'development'
)
```

#### Basic usage

Get USDT denominated ATOM in the spot market from Binance in `30m` intervals,

```{r example}
## get perpetual contracts on USDT denominated ATOM
spotPrice <- cryptoQuotes::getQuote(
ticker = 'ATOMUSDT',
source = 'binance',
futures = FALSE,
interval = '30m'
)
```
2 changes: 1 addition & 1 deletion man/ATOMUSDT.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions man/chart.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 16 additions & 30 deletions man/examples/scr_getQuote.R
Original file line number Diff line number Diff line change
@@ -1,35 +1,21 @@
# script: scr_getQuote
# date: 2023-09-22
# author: Serkan Korkmaz, [email protected]
# objective: demonstrate how to use
# the getQuote
# script start;

# gc
rm(list = ls()); invisible(gc())

# 1) load perpetual
# futures
#
# NOTE: The function is wrapped
# in try to avoid failing
# the R-CMD-CHECK on Github
perpAtom <- try(
cryptoQuotes::getQuote(
ticker = 'ATOMUSDT',
source = 'binance',
interval = '15m',
futures = TRUE
)
)


# 2) head data;
if (!inherits(perpAtom, 'try-error')) {

head(perpAtom)
\donttest{
# 1) load perpetual
# futures

perpAtom <- cryptoQuotes::getQuote(
ticker = 'ATOMUSDT',
source = 'binance',
interval = '15m',
futures = TRUE
)

# 2) chart the futures
cryptoQuotes::chart(
perpAtom
)

}



# script end;
Binary file modified man/figures/README-addBBands-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified man/figures/README-chartSeries-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions man/pipe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cc152a6

Please sign in to comment.