简体   繁体   English

java Yahoo finance api没有返回历史数据

[英]java Yahoo finance api not returning historical data

i am using Java Yahoo finance api for getting the stock historical data and stats. 我使用Java Yahoo finance api获取股票历史数据和统计数据。 from past 1 week its not returning the historical data. 从过去1周起,它没有返回历史数据。 is there any modification. 有任何修改。 I am using the following java code to get the historical data 我使用以下java代码来获取历史数据

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){}

} }

As an alternate, you can use this url - 作为替代方案,您可以使用此网址 -

https://query2.finance.yahoo.com/v8/finance/chart/ NHPC.NS ?formatted=true&crumb=6iPfwrHM.4i&lang=en-IN&region=IN&period1= 1501563799 &period2= 1502254999 &interval=1d&events=div|split&corsDomain=in.finance.yahoo.com https://query2.finance.yahoo.com/v8/finance/chart/ NHPC.NS ?formatted = true&crumb = 6iPfwrHM.4i&lang = en-IN&region = IN& period1 = 1501563799period2 = 1502254999 &interval = 1d&events = div | split&corsDomain = in。 finance.yahoo.com

This is the URL requested by your browser to https://in.finance.yahoo.com/ when you make a historical search of a stock in the Yahoo Finance Site. 当您在Yahoo Finance Site中对股票进行历史搜索时,这是您的浏览器请求的URL到https://in.finance.yahoo.com/

Check the screenshot - 检查截图 - 在此输入图像描述

The parameters that one have to change in the Script name, and the duration. 必须在脚本名称中更改的参数以及持续时间。 I was looking for the historical stock price of NHPC in NSE, that's why the script name is NHPC.NS 我在NSE寻找NHPC的历史股票价格,这就是为什么脚本名称是NHPC.NS

For setting the duration, you need to change the value of the parameters period1 and period2, period1 is start date and period2 is end date. 要设置持续时间,需要更改参数period1和period2的值,period1是开始日期,period2是结束日期。 The value of both the date parameters is in Unix epoch time. 两个日期参数的值都在Unix纪元时间内。 For converting Human Date to Unix epoch time check the tool: https://www.epochconverter.com/ 要将人类日期转换为Unix纪元时间,请检查工具: https//www.epochconverter.com/

In the URL that I have posted above, I am looking for the duration from 1st Aug to 9th Aug. 在我上面发布的网址中,我正在寻找从8月1日到8月9日的持续时间。
1-Aug-2017 (IST) - 1501563799 2017年8月1日(IST) - 1501563799
9-Aug-2017 (IST) - 1502254999 2017年8月9日(IST) - 1502254999

After you modify the above URL according to your criteria, make a Get request and you will get a Json Response which would something like this - 根据您的条件修改上述URL后,发出Get请求,您将得到一个类似这样的Json响应 - 在此输入图像描述

Now you can just write a Json parser for the response in your favorite language and use the historical data in your project accordingly. 现在,您可以用您喜欢的语言为响应编写Json解析器,并相应地使用项目中的历史数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM