R/public_ticker.R

Defines functions public_ticker

Documented in public_ticker

#' Get Latest Buy & Sell Trade.
#'
#' @name public_ticker
#'
#' @description Snapshot information about the last trade (tick), best bid/ask and 24h volume.
#'
#' @param product_id Optional character parameter. This is a case insensitive value of the product id for which the order book is desired. Default to \code{'BTC-USD'}. For all valid product ids, refer to \code{\link{public_info}}.
#'
#' @return  A dataframe of most recent trade and 24 hr volume.
#'
#' @examples
#' \dontrun{
#' public_ticker()
#' public_ticker("BTC-EUR")
#' }
#'
#' @export

# output tested on WIN. Macos pending.
public_ticker <- function(product_id = "BTC-USD") {
  #case remediation----
  product_id <- toupper(product_id)

  #get url extension----
  req.url <- paste0("/products/", product_id, "/ticker")

  #fetch response----
  response <- parse_response(path = req.url)

  #transform----
  content <- as.data.frame(fromJSON(rawToChar(response$content)))
  content$time <- strptime(content$time, "%Y-%m-%dT%H:%M:%OS")

  #return----
  return(content)
}

Try the rgdax package in your browser

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

rgdax documentation built on Aug. 3, 2021, 9:06 a.m.