-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
387 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.