MATLAB Answers

Datafeed returns an error using fetch function

7 views (last 30 days)
Hi everybody,
I'm trying to use "fetch" function with this code:
fetch(yahoo,'SPY',today())
but I recive this error:
Error using yahoo Unable to connect or retrieve data from given URL.
I used the same code 3 days ago and it worked. What's going on? Thanks!

  0 Comments

Sign in to comment.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 2 May 2017
The MathWorks Support Team recently posted an update on this issue. Here is the answer to save you the click:
“In April 2017, Yahoo introduced some changes in the protocol of their API. These changes prevented the Datafeed Toolbox from connecting to the service. The following webpage contains the workaround for this issue and instructions on how to apply the fix. https://www.mathworks.com/support/bugreports/1571158

  0 Comments

Sign in to comment.

More Answers (6)

Shashank
Shashank on 21 Apr 2017
Hi Adraino,
MATLAB uses Yahoo's API under the hood. Around April 18 Yahoo introduced some changes in the protocol of their API. These changes prevented the Datafeed Toolbox from connecting to the service.
The development team implemented a fix that takes into account those changes, but the fix needs to be applied manually. To apply the fix, follow these steps:
1) Download the attached files: 'yahoo.m' and 'fetch.m'
2) Remove the following file
%MATLAB_ROOT%\toolbox\datafeed\datafeed\@yahoo\yahoo.p
%MATLAB_ROOT%\toolbox\datafeed\datafeed\@yahoo\fetch.m
where %MATLAB_ROOT% can be found with the following MATLAB command:
>> matlabroot
3) Place the downloaded files in the following locations:
%MATLAB_ROOT%\toolbox\datafeed\datafeed\@yahoo\yahoo.m
%MATLAB_ROOT%\toolbox\datafeed\datafeed\@yahoo\fetch.m
4) Run the following MATLAB command
>> rehash toolboxcache
>> clear classes
Now you should be able to retrieve historic and current data as usual:
>> % Historic data
>> d = fetch(yahoo,'IBM','Close','01/01/2012','06/30/2012');
>> d(1:3,:)
>>
>> % Current data
>> fetch(yahoo,'IBM')

  5 Comments

Show 2 older comments
Walter Roberson
Walter Roberson on 14 Jun 2017
The attachments were withdrawn. Yahoo changed their system, disabling the interface that MATLAB used, and has not replaced it with anything useful as yet. You will not be able to get historical data from yahoo until Yahoo implements some new arrangment, and Mathworks writes a new routine to access it.

Sign in to comment.


Philippe Loustaunau
Philippe Loustaunau on 21 Apr 2017
I tried this and it is not working. First there is inconsistency in the answer: The file you provided is yahoo.m, but you suggest we delete yahoo.p. The yahoo.m file is in the datafeed directory, the yahoo.p file is in the @yahoo directory, inside the datafeed directory. Since you attached the yahoo.m file, I assume you wanted to replace the one in the datafeed directory. I followed the steps, but it is not working, same error.

  2 Comments

Duncan Aitken
Duncan Aitken on 25 Apr 2017
It works if you follow the instructions correctly.
The '@' character in the @yahoo folder name indicates that it's a class folder. Inside that folder are the class definition file and method files.
yahoo.p is an obfuscated version the yahoo class definition.
The new yahoo.m is a new yahoo class definition to replace the old one that was causing the error.
Replacing the yahoo.m in the datafeed directory was a mistake.

Sign in to comment.


Alexandre Amorim
Alexandre Amorim on 30 Apr 2017
Sweet!! Simple to solve and works fine!

  0 Comments

Sign in to comment.


avia gubbuy alon
avia gubbuy alon on 19 May 2017
again not working. please help.

  1 Comment

Denis Alaev
Denis Alaev on 18 Jun 2017
It seems that after several changes Yahoo Finance closed their API forever, I think that's just Verizon costs cutting strategy and I'm pretty sure this API will not be working again. The API was closed on May 15, one month ago already.
I've tested several alternatives and found that https://eodhistoricaldata.com the best one for those who used Yahoo Finance. They provide raw data, adjusted closes and splits/dividends.
They also have CSV output, with very similar format for Yahoo Finance users, API Documentation and even VBA Examples (https://eodhistoricaldata.com/knowledgebase/)
Also there is a https://intrinio.com/ data provider, looks good, but they much more expensive, have no data for Mutual Funds and API is very different in compare to Yahoo Finance. Then you need to significantly change your code.

Sign in to comment.


Munir Ruffo
Munir Ruffo on 29 May 2017
Where can i download the two mentioned files yahoo.m and fetch.m ? Can't find it anywhere!!
Thanks!

  0 Comments

Sign in to comment.


Adriano
Adriano on 29 May 2017
This is the Mathworks answer on my Technical Support on yahoo fetch function:
I sincerely apologize for the recent issues you may have encountered while connecting to the Yahoo service using the Datafeed Toolbox.
Yahoo has reportedly changed its API and site structure, which has resulted in the above error. According to Yahoo's forum, "ichart.yahoo.com" will undergo structural changes that will not cover existing functionality. Since "fetch" accesses "ichart.yahoo.com" to fetch historical and intraday data, connecting to Yahoo using the Datafeed Toolbox is no longer supported.

  0 Comments

Sign in to comment.