I'd like to download a stock quote from Yahoo Finance while the market is still open, to acquire that day's opening price. I'm trying to do this in R using getSymbols()
from the quantmod package:
#Acquire today's data as a string
today.char <- Sys.Date() %>% as.character
#Download stock quote during market hours
currentQuote <- getSymbols('QQQ',
from = today.char,
src = "yahoo",
env = NULL)
However, this results in the following error:
Error in download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=QQQ&a=5&b=20&c=2016&d=5&e=20&f=2016&g=d&q=q&y=0&z=QQQ&x=.csv'
In addition: Warning message:
In download.file(paste(yahoo.URL, "s=", Symbols.name, "&a=", from.m, :
cannot open URL 'http://ichart.finance.yahoo.com/table.csv?s=QQQ&a=5&b=20&c=2016&d=5&e=20&f=2016&g=d&q=q&y=0&z=QQQ&x=.csv': HTTP status was '404 Not Found'
What am I doing wrong, and how can I obtain at least an opening price before market close?
would getQuote()
work for you? for instance getQuote('X')[5]
would give you todays opening price for US STEEL, and the rest of the quote is in the data frame returned by `getQuote()'