Currently, I am utilizing jQuery and highcharts.js to develop a single line chart on my website that displays historical financial data for any company specified by the user. I have been experimenting with YQL and employed this query to fetch some quotes in JSON format:
select * from yahoo.finance.historicaldata where symbol = "AAPL" and startDate = "2013-02-01" and endDate = "2013-02-25"
Here is a link to the YQL console containing my query:
http://developer.yahoo.com/yql/console/?q=show%20tables&env=store://datatables.org/alltableswithkeys#h=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22AAPL%22%20and%20startDate%20%3D%20%222013-02-01%22%20and%20endDate%20%3D%20%222013-02-25%22
The output includes details about execution-start-time and execution-end-time, followed by the desired quotes:
"results": {
"quote": [
{
"date": "2013-02-25",
"Date": "2013-02-25",
"Open": "453.85",
"High": "455.12",
"Low": "442.57",
"Close": "442.80",
"Volume": "13306400",
"Adj_Close": "442.80"
},
I am encountering an issue extracting the Close price information from the results. I've attempted the following code without success:
$.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22AAPL%22%20and%20startDate%20%3D%20%222013-02-01%22%20and%20endDate%20%3D%20%222013-02-25%22&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=cbfunc', function(data){
console.log(data);
var close = data.query.results.quote.close;
document.write(close);
})
If anyone can assist me in identifying where my mistake lies, it would be greatly appreciated as I am new to jquery, yql, and json.
Thank you