JSON formatted stock quote API (live or historical)

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)

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.