Java Yahoo finance api not returning historical data
I am using Java Yahoo finance api to get historical data and statistics. since the last 1 week it hasn't returned any historical data. is there any modification. I am using the following java code to get historical data
Map<String, Stock> stocks = YahooFinance.get(symbols_array, from, to, Interval.DAILY);
for (int i = 0; i <= index; i++) {
try {
Stock element = stocks.get(symbols_array[i]);
StockQuote element_quote = element.getQuote();
StockStats element_stats = element.getStats();
List<HistoricalQuote> hist_list = element.getHistory();
}
catch(Exception e){}
}
source to share
Alternatively, you can use this url -
https://query2.finance.yahoo.com/v8/finance/chart/ NHPC.NS ? formatted = true & crumb = 6iPfwrHM.4i & lang = en -IN & area = IN & period1 = 1501563799 & period2 = 1502254999 & interval = 1d & events = DIV | split & corsDomain = in.finance.yahoo.com
This is the URL requested by your browser at https://in.finance.yahoo.com/ when you do a historical search for stocks on the Yahoo Finance site.
Parameters to be changed in Script name and duration. I was looking for the historical NHPC stock price in the NSE, so the name of the Script is NHPC.NS
To set the duration, you need to change the value of the period1 and period2 parameters, period1 is the start date, and period2 is the end date. The value of both date parameters is specified at a Unix time. To convert Human Date to Unix check the tool: https://www.epochconverter.com/
In the URL I posted above, I'm looking for the duration from Aug 1st to Aug 9th.
1-Aug-2017 (IST) - 1501563799
9-Aug-2017 (IST) - 1502254999
After changing the above url to match your criteria, make a Get request and you will get a Json response that looks something like this:
Now you can simply write a Json parser for the response in your favorite language and use the historical data accordingly in your project.
source to share