1
votes

I found an answer to my own question (see below). Still need help.

In the same package, quantmod, there is an option called getSymbol.google.

Nevertheless,

If I use it to get Microsoft value, for example, it works all right

getSymbols.google('MSFT', environment() , src="google", from = (Sys.Date() - 1))

[1] "MSFT"

But, I can´t make it work on a currency pair;

getSymbols.google("GBPUSD", environment() , src="google", from = (Sys.Date() - 1))

Error in download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", : cannot open URL 'http://finance.google.com/finance/historical?q=GBPUSD&startdate=Nov+02,+2017&enddate=Nov+03,+2017&output=csv' In addition: Warning message: In download.file(paste(google.URL, "q=", Symbols.name, "&startdate=", : cannot open URL 'http://finance.google.com/finance/historical?q=GBPUSD&startdate=Nov+02,+2017&enddate=Nov+03,+2017&output=csv': HTTP status was '400 Bad Request'

Any ideas?

Good morning,

Since the 1ts of November i´m having trouble with the function getQuote from Yahoo. Is a function inside the package "quantmod", which uses yahoo API to request the information.

The description of the function is as follows; Fetch current stock quote(s) from specified source. At present this only handles sourcing quotes from Yahoo Finance, but it will be extended to additional sources over time.

In r, i´m getting the following error; "HTTP status was '403 Forbidden'"

I´ve look on my browser and the error comes from the following error in Yahoo web page "Fetch current stock quote(s) from specified source. At present this only handles sourcing quotes from Yahoo Finance, but it will be extended to additional sources over time."

Does anybody know how to solve ir, or, any alternatives to the function getQuote()

Here is an example from RStudio

getQuote("AAPL")
Error in download.file(paste("https://finance.yahoo.com/d/quotes.csv?s=", : cannot open URL 'https://finance.yahoo.com/d/quotes.csv?s=AAPL&f=d1t1l1c1p2ohgv' In addition: Warning message: In download.file(paste("https://finance.yahoo.com/d/quotes.csv?s=", : cannot open URL 'https://finance.yahoo.com/d/quotes.csv?s=AAPL&f=d1t1l1c1p2ohgv': HTTP status was '403 Forbidden'

Thanks

2

2 Answers

0
votes

seems that yahoo has discontinued this service. Anyone aware of a alternative for yahoo (I'd rather not have to webscrape yahoo for this)

rob

0
votes

I ran into the same problem... it's kludgey but as a workaround to get the end-of-day value, I have found this to work for now:

Instead of getQuote() to get the Last price (which doesn't seem to work from Yahoo anymore):

underlying<-"AAPL"
quote.last <-getQuote(underlying)$Last

I use "getSymbols" which still works-- throws it into a new data frame, and I pull out the value I want from that:

Hx<-getSymbols(underlying,from=Sys.Date()-1) # allows me to not have to retain the ticker name if I do this across many tickers
quote.last<-as.double(tail(Cl(get(Hx)),1)) # Closing price value from last row of data
rm(list=Hx) # throw away the temporary data frame with quote history

I'm sure the's a more elegant way to do it, but this is what fell out of my brain as a quick workaround that got it done... sadly that doesn't get things like the Bid and Ask that getQuote does.