oercim
oercim

Reputation: 1848

Started to get error while downloading data from yahoo finance using R

I started to get an error while downloading some stock's data from yahoo finance web site in R. I am using get.hist.quote function from tseries package .

Last week, there was no problem.

May code is as below:

library(tseries)

data<-get.hist.quote(instrument = "EREGL.IS,
                     provider="yahoo",
                     quote=c("Open","High","Low","Close","AdjClose","Volume"),
                     start="2010-01-01",
                     end="2017-02-03",
                     compression="d",
                     retclass="zoo")

`

I get the below error:

trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
download error, retrying ...
trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
download error, retrying ...
trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
download error, retrying ...
trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
download error, retrying ...
trying URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
Error in get.hist.quote(instrument = "EREGL.IS", provider = "yahoo", quote = c("Open",  : 
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv'
In addition: Warning messages:
1: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'
2: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'
3: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'
4: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'
5: In download.file(url, destfile, method = method, quiet = quiet) :
  cannot open URL 'https://ichart.finance.yahoo.com/table.csv?s=EREGL.IS&a=0&b=01&c=2010&d=1&e=03&f=2017&g=d&q=q&y=0&z=EREGL.IS&x=.csv': HTTP status was '504 Maximum Transaction Time Exceeded'

Why do I get this error? One possibility is changing name of the related url.

How can I fix this problem? I will be very glad for any help. Thanks a lot.

Upvotes: 0

Views: 1591

Answers (1)

Eldioo
Eldioo

Reputation: 522

Yahoo made some changes, so you can't access the download without the respective "crumb", see Question few days ago.
Unless you want to manually copy-paste this Download-URL for each stock, I'd highly suggest you to use the quantmod package. It works, after applying a short fix (which will probably soon be included in a new package version - until then you have to do it manually).

library(quantmod)   #probably will need to install the package first
devtools::install_github("joshuaulrich/quantmod", ref="157_yahoo_502")    #installing the fix (devtools necessary)

str(getSymbols("EREGL.IS",auto.assign=F,from="2010-01-01",to="2017-02-03"))    #Example
#An ‘xts’ object on 2010-01-01/2017-02-03 containing:
#  Data: num [1:1851, 1:6] 4.39 4.43 4.42 4.49 4.49 ...
# - attr(*, "dimnames")=List of 2
#  ..$ : NULL
#  ..$ : chr [1:6] "EREGL.IS.Open" "EREGL.IS.High" "EREGL.IS.Low"     #"EREGL.IS.Close" ...
#  Indexed by objects of class: [Date] TZ: UTC
#  xts Attributes:  
#List of 2
# $ src    : chr "yahoo"
# $ updated: POSIXct[1:1], format: "2017-05-20 12:11:08"

Upvotes: 2

Related Questions