R/api_fundamentals.R

Defines functions api_fundamentals

Documented in api_fundamentals

#' RobinHood API: Fundamentals
#'
#' Backend function called by get_fundamentals(), watchlist(). Returns a data frame of descriptive data for a
#' given ticker symbol.
#'
#' @param RH object of class RobinHood
#' @param ticker (string) vector of ticker symbols
#' @import httr magrittr

api_fundamentals <- function(RH, ticker) {

  # URL and token
  url <- paste(api_endpoints("fundamentals"), ticker, collapse = ",", sep = "")
  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$results)

  dta <- dta %>%
    dplyr::mutate_at(c("open", "high", "low", "volume", "average_volume_2_weeks", "average_volume", "high_52_weeks",
                       "dividend_yield", "low_52_weeks", "market_cap", "pe_ratio", "shares_outstanding"),
                     as.numeric)

  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 Oct. 6, 2019, 5:05 p.m.