JSON 格式的股票报价 API(实时或历史)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13458132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 18:37:42  来源:igfitidea点击:

JSON formatted stock quote API (live or historical)

jsonrestyqlyahoo-finance

提问by bouncingHippo

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 notreturn XML and does notuse C#.

我正在为自己构建一个 RESTful Web 应用程序,我有兴趣免费获取 JSON 格式的股票数据。我计划在客户端使用 javascript。有一个免费的股票API,我可以挖掘到,这并没有返回XML和它没有使用C#。

EDIT: i found this JSON query...will it do the job?

编辑:我发现了这个 JSON 查询……它能完成这项工作吗?

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

回答by crowebird

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:

当然,如果使用 javascript 返回并解析为 JSON,您将能够执行以下操作并从每个返回的库存中提取您想要的所有内容:

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);

--

——

YQL Demo

YQL 演示

(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)

startDate = "" and endDate = ""使用 yyyy-mm-dd 格式的日期将 和 添加到查询中以执行您想要的操作,同时确保选择 JSON 作为输出格式)

--

——

Some additional information from the comments:

评论中的一些附加信息:

  • 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=detailto that query if you want a more detailed output)
  • 在上面的示例中,查询来自 yahoo.finance.historicaldata 的历史数据,您还可以实时查询 yahoo.finance.quotes -- 滞后大约 15 分钟)
  • 如果您想要真正的实时信息,请查询网络服务:例如finance.yahoo.com/webservice/v1/symbols/YHOO/quote?format=json&view=detail如果您想要更详细的输出,请添加到该查询中)

回答by Steve Carino

As a software developer, I would recommend Alpha Vantage. They offer realtime and historical stock quotes (daily, weekly, monthly, etc.) as RESTful JSON APIs.

作为软件开发人员,我会推荐Alpha Vantage。它们以RESTful JSON API 的形式提供实时和历史股票报价(每日、每周、每月等)。

It's completely free with unlimited API calls. It's realtime as long as the stock is listed on major stock exchanges.

它是完全免费的,具有无限的 API 调用。只要股票在主要证券交易所上市,它就是实时的。

Hereis an example API call for the MSFT daily prices and volumes, enriched with split/dividend adjustments. The latest data point is the realtime information for the current trading day.

以下是 MSFT 每日价格和交易量的示例 API 调用,并通过拆分/股息调整进行了丰富。最新数据点是当前交易日的实时信息。

They also offer technical analysis APIs on top of the market data according to their documentation.

他们还根据他们的文档在市场数据之上提供技术分析 API。

回答by Timothy Gonzalez

Documentation: https://iextrading.com/developer/docs/#stocks

文档:https: //iextrading.com/developer/docs/#stocks

GET https://api.iextrading.com/1.0/stock/jnj/quote

获取https://api.iextrading.com/1.0/stock/jnj/quote

{
    "symbol": "JNJ",
    "companyName": "Johnson & Johnson",
    "primaryExchange": "New York Stock Exchange",
    "close": 124.69,
    "closeTime": 1531771224535
}