R/download_crypto_data.R

Defines functions download_crypto_data

Documented in download_crypto_data

#' Download crypto data
#'
#' Helper function to download data from the BRC
#'
#' @param LINK a link from the BRC.
#' @param PATH the path where the data should be downloaded to.

#' @export
download_crypto_data <- function(LINK, PATH ="./data/raw/csv_dump/"){
  paste("Opening path", PATH)
  if (length(sort(list.files(path = PATH, pattern = "*.csv"))) == 0) {
      print("Downloading and saving data...")
      DT_CRYPTO <- fread(LINK)
      filename <- gsub("https://cryptotrades-exports.s3.eu-central-1.amazonaws.com/trade-exports/", "", LINK)
      target_path <- paste(PATH, filename, sep = "")
      fwrite(DT_CRYPTO, target_path)
    } else {
      print(paste("Error:", PATH, "not empty. No files downloaded. Do you really want to redownload the data? If that's the case please make sure the target directory is empty."))
    }
}
YalDan/hf.econometrics documentation built on May 10, 2024, 2:18 a.m.