Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
update.realtime <-
function(ticker, history = NULL)
{
if (is.null(history)) {
history <- getSymbols(ticker, from = "2018-01-01", auto.assign = FALSE)
}
today <- getQuote(ticker, src = "yahoo")
now <- as.Date(today[,"Trade Time"])
cn <- c("Open", "High", "Low", "Last", "Volume", "Last")
live <- xts(today[, cn], now)
if (end(history) == now) {
output <- history
output[now, ] <- live
} else {
output <- rbind(history, live)
}
output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment