I am able to get stock prices from Google Finance using Angular JS $resource with JSONP. This is shown here: http://jsfiddle.net/8zVxH/1/
I need historical prices, which Google does not provide, but Yahoo does. I modified the above jsfiddle to this: http://jsfiddle.net/curt00/BqtzB/
Here's the code:
angular.module('app', ['ngResource']);
function AppCtrl($scope, $resource) {
var yqlURL="http://query.yahooapis.com/v1/public/yql?q=";
var dataFormat="&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
var symbol = 'GOOG';
var startDate = '2012-12-05';
var endDate = '2012-12-06';
var historical_query = yqlURL+"select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22"+ symbol +"%22%20and%20startDate%20%3D%20%22"+ startDate +"%22%20and%20endDate%20%3D%20%22"+ endDate +"%22"+ dataFormat;
$scope.yahooFinance = $resource(historical_query,
{callback:'JSON_CALLBACK'},
{get: {method:'JSONP', isArray: false}});
$scope.indexResult = $scope.yahooFinance.get();
}
It generates an error message in the browser console:
GET http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22GOOG%22%20and%20startDate%20%3D%20%222012-12-05%22%20and%20endDate%20%3D%20%222012-12-06%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys?callback=angular.callbacks._0 400 (Bad Request)
Does anybody know how to get this to work?
I know that Jquery's getJSON can be used with this Yahoo query, but supposedly AngularJS' $resource is faster and more efficient.