I have a java software which requests both, current and historical stock prices from yahoo finance.
As described in other posts, yahoo can write the prices to a file, which can be read by a scanner. To request the current price of amazon i call: http://finance.yahoo.com/d/quotes.csv?s=AMZ.DE&f=snl1t1c4
To request amazons prices in the past 5 years i call: http://ichart.finance.yahoo.com/table.csv?s=AMZ.DE&d=3&e=20&f=2017&a=3&b=20&c=2012&g=d&ignore=.cvs
If I access these two links in my browser, it downloads a .csv file with the expected data for each of them.
In java the corresponding .csv file should be read by the folling method:
private static List<String> requestStockData(String request) throws IOException {
Scanner scanner = null;
List<String> answer = new ArrayList();
try {
scanner = new Scanner(new URL(request).openStream());//no exception here
} catch (FileNotFoundException e) {
Tools.printDebugMessage("Received null-answer for request " + request);
return answer;
}
while (scanner.hasNextLine()) {//scanner.hasNextLine() returns false
String value = scanner.nextLine();
answer.add(value);
Tools.printDebugMessage("received answer from YAHOO! Finance: " + value);
}
scanner.close();
return answer;
}
where request is one of the links above.
I am using this software for a few weeks, and it worked perfectly. But the last days it does not work for the historical data anymore, but it works fine for the current data.
Using the link to the historical data the scanner will be opened normally and does not throw an exception, but scanner.hasNextLine() will return false instantly, but the .csv file, downloaded with my browser, has 1305 lines.
Does anyone of you understand why the scanner does not accept the .csv files for the historical data anymore but accepts the current data ones?
Update your url with "https" and try again.
old : http://ichart.finance.yahoo.com/table.csv?s=AMZ.DE&d=3&e=20&f=2017&a=3&b=20&c=2012&g=d&ignore=.cvs
new : https://ichart.finance.yahoo.com/table.csv?s=AMZ.DE&d=3&e=20&f=2017&a=3&b=20&c=2012&g=d&ignore=.cvs
received answer from YAHOO! Finance: Date,Open,High,Low,Close,Volume,Adj Close
received answer from YAHOO! Finance: 2017-04-19,844.95,849.35,842.90,847.90,1700,847.90
received answer from YAHOO! Finance: 2017-04-18,849.50,851.00,841.25,845.00,3100,845.00
received answer from YAHOO! Finance: 2017-04-17,839.90,839.90,839.90,839.90,000,839.90