Skip to content

Commit

Permalink
Adapt crypto_history() function to accept modified lists as input for…
Browse files Browse the repository at this point in the history
… the coin retrieval e.g. gathered using a custom version of rypto_list().
  • Loading branch information
sstoeckl committed Mar 20, 2019
1 parent 0a415e2 commit 35645c5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 14 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ importFrom(rvest,"html_table")
importFrom(tibble,"as.tibble")
importFrom(tibble,"as_tibble")
importFrom(tibble,'as.tibble')
importFrom(tibble,'as_tibble')
importFrom(tibble,'tibble')
importFrom(tibble,tibble)
importFrom(tidyr,"separate")
Expand Down
19 changes: 11 additions & 8 deletions R/crypto_history.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
#' analysis on the crypto financial markets or to attempt
#' to predict future market movements or trends.
#'
#' @param coin string Name, symbol or slug of crypto currency, default is all tokens
#' @param coins string if NULL retrieve all currently existing coins (crypto_list()),
#' or provide list of crypto currencies in the crypto_list() format (e.g. current and dead coins since 2015)
#' @param limit integer Return the top n records, default is all tokens
#' @param start_date string Start date to retrieve data from, format 'yyyymmdd'
#' @param end_date string End date to retrieve data from, format 'yyyymmdd'
Expand All @@ -18,7 +19,6 @@
#' \item{symbol}{Coin symbol}
#' \item{name}{Coin name}
#' \item{date}{Market date}
#' \item{ranknow}{Current Rank}
#' \item{open}{Market open}
#' \item{high}{Market high}
#' \item{low}{Market low}
Expand All @@ -35,7 +35,7 @@
#' @importFrom tidyr 'replace_na'
#' @importFrom crayon 'make_style'
#' @importFrom grDevices 'rgb'
#' @importFrom tibble 'tibble' 'as.tibble'
#' @importFrom tibble 'tibble' 'as_tibble'
#' @importFrom cli 'cat_bullet'
#' @importFrom lubridate 'mdy'
#'
Expand All @@ -50,12 +50,16 @@
#'
#' # Retrieving this years market history for ALL crypto currencies
#' all_coins <- crypto_history(start_date = '20180101')
#'
#' # Retrieve 2015 history for all 2015 crypto currencies
#' coin_list_2015 <- crypto_list(start_date_hist="20150101",end_date_hist="20151231",date_gap="months")
#' 2015_coins <- crypto_history(coins = coin_list_2015, start_date = "20150101", end_date="20151231")
#' }
#' @name crypto_history
#'
#' @export
#'
crypto_history <- function(coin = NULL, limit = NULL, start_date = NULL, end_date = NULL,
crypto_history <- function(coins = NULL, limit = NULL, start_date = NULL, end_date = NULL,
coin_list = NULL, sleep = NULL) {
pink <- crayon::make_style(grDevices::rgb(0.93, 0.19, 0.65))
options(scipen = 999)
Expand All @@ -70,14 +74,13 @@ crypto_history <- function(coin = NULL, limit = NULL, start_date = NULL, end_dat
message("ERC-20: 0x375923Bf82F0b728d23A5704261a6e16341fd860", appendLF = TRUE)
message("XRP: rK59semLsuJZEWftxBFhWuNE6uhznjz2bK", appendLF = TRUE)
message("\n")
# only if no coin_list is provided
if (is.null(coin_list)) coins <- crypto_list(coin, start_date, end_date, coin_list)
# only if no coins are provided
if (is.null(coins)) coins <- crypto_list(coin, start_date, end_date, coin_list)

if (!is.null(limit))
coins <- coins[1:limit, ]

coin_names <- tibble::tibble(symbol = coins$symbol, name = coins$name, rank = coins$rank,
slug = coins$slug)
coin_names <- tibble::tibble(symbol = coins$symbol, name = coins$name,slug = coins$slug)
to_scrape <- tibble::tibble(attributes = coins$history_url, slug = coins$slug)
loop_data <- vector("list", nrow(to_scrape))

Expand Down
2 changes: 1 addition & 1 deletion R/crypto_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#' coin_list <- crypto_list()
#'
#' # return all coins listed in 2015
#' coins_list_2015 <- crypto_list(start_date_hist="20150101",end_date_hist="20151231",date_gap="months")
#' coin_list_2015 <- crypto_list(start_date_hist="20150101",end_date_hist="20151231",date_gap="months")
#'
#' }
#'
Expand Down
10 changes: 7 additions & 3 deletions man/crypto_history.Rd

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

3 changes: 1 addition & 2 deletions man/crypto_list.Rd

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

0 comments on commit 35645c5

Please sign in to comment.