JSON formatted stock quote API (live or historical)

自作多情 提交于 2019-11-28 14:52:13

问题


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#.

EDIT: 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

回答1:


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

--

YQL Demo

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

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



回答2:


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

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

Here is 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.

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




回答3:


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

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

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


来源:https://stackoverflow.com/questions/13458132/json-formatted-stock-quote-api-live-or-historical

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!