JSON格式的股票报价API(实时或历史记录) [英] JSON formatted stock quote API (live or historical)
问题描述
我正在为自己构建一个RESTful Web应用程序,我对免费获取JSON格式的库存数据感兴趣.我计划在客户端使用javascript.我可以使用免费的免费API,它不返回XML,并且不使用C#.
i am building a RESTful web app for myself and i'm interested in getting JSON-formatted stock data for free. I plan to use javascript for the client-side. Is there a free stock API that i can tap into, that does not return XML and does not use C#.
我发现了这个JSON查询...它将完成这项工作吗?
i found this JSON query...will it do the job?
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22YHOO%22%2C%22AAPL%22%2C%22GOOG%22%2C%22MSFT%22)%0A%09%09&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json
推荐答案
当然,如果使用javascript将其带回并解析为JSON,您将可以执行以下操作,并从每只退回的存货中提取所需的一切:>
Sure, if brought back and parsed as JSON with javascript, you would be able to do the following and pull out everything you wanted from each returned stock:
var callback = function(_return /* The json returned for yahooapis */) {
var totalReturned = _return.query.count;
//OR: var totalReturned = _return.query.results.quote.length;
for (var i = 0; i < totalReturned; ++i) {
var stock = _return.query.results.quote[i];
var symbol = stock.symbol;
var percent_change = stock.Change_PercentChange;
var changeRealTime = stock.ChangeRealtime;
...
}
}
-
var url = 'http://query.yahooapis.com/v1/public/yql';
var startDate = '2012-01-01';
var endDate = '2012-01-08';
var data = encodeURIComponent('select * from yahoo.finance.historicaldata where symbol in ("YHOO","AAPL","GOOG","MSFT") and startDate = "' + startDate + '" and endDate = "' + endDate + '"');
$.getJSON(url, 'q=' + data + "&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json", callback);
-
(将日期格式为yyyy-mm-dd的查询添加和startDate = "" and endDate = ""
以执行所需的操作,还请确保选择JSON作为输出格式)
(Add and startDate = "" and endDate = ""
to the query with the dates in the format yyyy-mm-dd to do what you want, also make sure to choose JSON as the output format)
-
评论中的一些其他信息:
Some additional information from the comments:
- 在上面的示例中,查询的是来自yahoo.finance.historicaldata的历史数据,您也可以实时查询yahoo.finance.quotes -大约滞后15分钟)
- 如果您想要真实的实时信息,请查询网络服务:例如
finance.yahoo.com/webservice/v1/symbols/YHOO/quote?format=json
(如果需要更详细的输出,请在该查询中添加&view=detail
)
- In the example above the query was for historical data from yahoo.finance.historicaldata, you can also query yahoo.finance.quotes for realtime -- lagged about 15 minutes)
- If you want true real-time information query the webservice: e.g.
finance.yahoo.com/webservice/v1/symbols/YHOO/quote?format=json
(add&view=detail
to that query if you want a more detailed output)
这篇关于JSON格式的股票报价API(实时或历史记录)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!