You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems Alphavantage's API has changed and they do not have batch quotes anymore. Only single quote, like this. So current getQuote.av does not work anymore. Related to #213
Expected behavior
Being able to get quotes from Alphavantage anytime with personal API key.
Minimal, reproducible example
getQuote(c('IBM','F'), src='av', api.key='yourOwn') # No data for symbols: IBM, F
Proposed patch
getQuote.av<-function (Symbols='A;B;F', api.key, verbose=FALSE) {
# get latest daily quotes from AV, they dont have batch quotes anymore as of Feb 2020
importDefaults("getQuote.av")
if (!hasArg("api.key")) {
stop("getQuote.av: An API key is required (api.key). Free registration,",
" at https://www.alphavantage.co/.", call.=FALSE)
}
if (length(Symbols) >1&& is.character(Symbols)) # accept vector tooSymbols<- paste(Symbols, collapse=";")
Symbols<- unique(unlist(strsplit(Symbols, ";")))
length.of.symbols<- length(unlist(strsplit(Symbols, ";")))
if (length.of.symbols==0)
stop('no symbols provided', call.=FALSE)
if (verbose) cat('\n getting quotes: ')
qdf<-data.frame()
for (iin1:length.of.symbols) {
Sys.sleep(0.5)
if (verbose) cat(Symbols[i], "")
url<- paste0('https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=',Symbols[i],'&apikey=',api.key)
dd<-jsonlite::fromJSON(url)
if (names(dd[1])=="Error Message") next# skip invalid symbolsdd<-dd[[1]] # dd$`Global Quote`dd[2:6] <- sapply(dd[2:6], as.numeric)
tmpdf<-data.frame(symbol= toupper(Symbols[i]),
date= as.Date(dd$`07. latest trading day`),
open=if (is.null(dd$`02. open`)) 0elsedd$`02. open`,
high=if (is.null(dd$`03. high`)) 0elsedd$`03. high`,
low=if (is.null(dd$`04. low`)) 0elsedd$`04. low`,
close=dd$`05. price`,
volume=if (is.null(dd$`06. volume`)) 0elsedd$`06. volume` )
qdf<- rbind(qdf, tmpdf)
}
if (verbose) cat('done.\n')
rownames(qdf) <-qdf$symbolqdf$symbol<-NULLqdf
}
The text was updated successfully, but these errors were encountered:
Alphavantage returns NULL for all the columns of data for requests on
invalid symbols. We need to set the Symbol column to the value of the
symbol input in order to return a row of NA for the symbol in the
results, as we do for other getQuote() methods.
See #296.
Description
It seems Alphavantage's API has changed and they do not have batch quotes anymore. Only single quote, like this. So current getQuote.av does not work anymore. Related to #213
Expected behavior
Being able to get quotes from Alphavantage anytime with personal API key.
Minimal, reproducible example
Proposed patch
The text was updated successfully, but these errors were encountered: