R/api_historicals_crypto.R

Defines functions api_historicals_crypto

Documented in api_historicals_crypto

#' RobinHood API: Historicals crypto
#'
#' Backend function called by get_historicals_crypto(). Returns a data frame of historical price data.
#'
#' @param RH object of class RobinHood
#' @param url (string) full url coming from get_historicals_crypto
#' @import httr magrittr
#' 
api_historicals_crypto <- function(RH, url) {

  # url to get historical data
  token <- paste("Bearer", RH$tokens.access_token)

  # GET call
  dta <- GET(url,
             add_headers("Accept" = "application/json",
                         "Content-Type" = "application/json",
                         "Authorization" = token))

  # Format return
  dta <- mod_json(dta, "fromJSON")
  dta <- as.data.frame(dta$data_points)

  return(dta)
}

Try the RobinHood package in your browser

Any scripts or data that you put into this service are public.

RobinHood documentation built on March 1, 2021, 5:08 p.m.