<!DOCTYPE html>
<html ng-app='app'>
<head>
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="style.css" rel="stylesheet">
<link href="http://code.ionicframework.com/0.9.26/css/ionic.css" rel="stylesheet" type="text/css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script src="http://code.ionicframework.com/0.9.26/js/ionic.js"></script>
<script src="http://code.ionicframework.com/0.9.26/js/angular/angular.min.js"></script>
<script src="http://code.ionicframework.com/0.9.26/js/angular/angular-animate.min.js"></script>
<script src="http://code.ionicframework.com/0.9.26/js/angular/angular-touch.min.js"></script>
<script src="http://code.ionicframework.com/0.9.26/js/angular/angular-sanitize.min.js"></script>
<script src="http://code.ionicframework.com/0.9.26/js/angular-ui/angular-ui-router.min.js"></script>
<script src="http://code.ionicframework.com/0.9.26/js/ionic-angular.js"></script>
<!--Main application-->
<script src="main.js"></script>
<!--some api functions for yahoo finance-->
<script src="yahooStock.js"></script>
</head>
<body ng-controller='mainCtrl'>
<ion-side-menus>
<ion-pane ion-side-menu-content>
<header class="bar bar-header bar-dark">
<h1 class="title">Stocks</h1>
</header>
<ion-content has-header="true">
GOOG has Book Value Per Share of: {{data}}
<!-- our list and list items -->
<ion-list>
<ion-item ng-repeat="stock in stocks">
{{stock.title}}
</ion-item>
</ion-list>
</ion-content>
</ion-pane>
<!-- Left menu -->
<ion-side-menu side="left">
<!--Just filling it up with some content-->
<ion-header-bar title="'Stuff'"></header-bar>
<ion-item ng-repeat='stuff in stuffs'>
{{stuff}}
</ion-item>
</ion-side-menu>
</ion-side-menus>
</body>
</html>
/* Styles go here */
/**
* Hey Ning, I just migrated these functions from python (find and replace) from the github file below. To convert them to javascript from python,
* derived from:
*
* https://github.com/cgoldberg/ystockquote/blob/master/ystockquote.py
*
* and the api is specced out here. Apparently yahoo has its own query language (looks like sql..)
*
* https://code.google.com/p/yahoo-finance-managed/wiki/YahooFinanceAPIs
*
* I just templated a query based on this example.
*
* http://www.ask-coder.com/3877638/displaying-ajax-results-from-yahoo-finance-using-underscore-js
*
* Hope you have fun with javscript, Don't worry this only took me like 20 mintues to setup :D
*
*/
angular.module('app').factory('yahooStock',function($http){
//yahoo query api
var yqlUrl = "http://query.yahooapis.com/v1/public/yql";
//historical api queryied by yql..
var historicalUrl = 'http://finance.yahoo.com/d/quotes.csv';
//template to put query params into
var queryTemplate = _.template("select * from csv where url='" + historicalUrl + "?s=<%= symbol %>&f=<%= code %>'");
function _request(symbol,code){
return $http({
method:"GET",
url: yqlUrl,
params: {q: queryTemplate({symbol:symbol,code:code}), format: 'json'}
}).then(function(response){
console.log('response',response.data);
return {data:response.data.query.results.row['col0']};
});
}
var factory = {
getDividendYield: function(symbol){
return _request(symbol, 'y');},
getDividendPerShare: function(symbol){
return _request(symbol, 'd');},
getAskRealtime: function(symbol){
return _request(symbol, 'b2');},
getDividendPayDate: function(symbol){
return _request(symbol, 'r1');},
getBidRealtime: function(symbol){
return _request(symbol, 'b3');},
getExDividend_date: function(symbol){
return _request(symbol, 'q');},
getPreviousClose: function(symbol){
return _request(symbol, 'p');},
getTodayOpen: function(symbol){
return _request(symbol, 'o');},
getChange: function(symbol){
return _request(symbol, 'c1');},
getLastTradeDate: function(symbol){
return _request(symbol, 'd1');},
getChangePercentChange: function(symbol){
return _request(symbol, 'c');},
getTradeDate: function(symbol){
return _request(symbol, 'd2');},
getChangeRealtime: function(symbol){
return _request(symbol, 'c6');},
getLastTradeTime: function(symbol){
return _request(symbol, 't1');},
getChangePercentRealtime: function(symbol){
return _request(symbol, 'k2');},
getChangePercent: function(symbol){
return _request(symbol, 'p2');},
getAfterHoursChange: function(symbol){
return _request(symbol, 'c8');},
getChange200sma: function(symbol){
return _request(symbol, 'm5');},
getCommission: function(symbol){
return _request(symbol, 'c3');},
getPercentChange200sma: function(symbol){
return _request(symbol, 'm6');},
getTodaysLow: function(symbol){
return _request(symbol, 'g');},
getChange50sma: function(symbol){
return _request(symbol, 'm7');},
getTodaysHigh: function(symbol){
return _request(symbol, 'h');},
getPercentChange50sma: function(symbol){
return _request(symbol, 'm8');},
getLastTradeRealtimeTime: function(symbol){
return _request(symbol, 'k1');},
get50sma: function(symbol){
return _request(symbol, 'm3');},
getLastTradeTimePlus: function(symbol){
return _request(symbol, 'l');},
get200sma: function(symbol){
return _request(symbol, 'm4');},
getLastTradePrice: function(symbol){
return _request(symbol, 'l1');},
get1yearTarget: function(symbol){
return _request(symbol, 't8');},
getTodaysValueChange: function(symbol){
return _request(symbol, 'w1');},
getHoldingsGainPercent: function(symbol){
return _request(symbol, 'g1');},
getTodaysValueChangeRealtime: function(symbol){
return _request(symbol, 'w4');},
getAnnualizedGain: function(symbol){
return _request(symbol, 'g3');},
getPricePaid: function(symbol){
return _request(symbol, 'p1');},
getHoldingsGain: function(symbol){
return _request(symbol, 'g4');},
getTodaysRange: function(symbol){
return _request(symbol, 'm');},
getHoldingsGainPercentRealtime: function(symbol){
return _request(symbol, 'g5');},
getTodaysRangeRealtime: function(symbol){
return _request(symbol, 'm2');},
getHoldingsGainRealtime: function(symbol){
return _request(symbol, 'g6');},
get52WeekHigh: function(symbol){
return _request(symbol, 'k');},
getMoreInfo: function(symbol){
return _request(symbol, 'v');},
get52WeekLow: function(symbol){
return _request(symbol, 'j');},
getMarketCap: function(symbol){
return _request(symbol, 'j1');},
getChangeFrom52WeekLow: function(symbol){
return _request(symbol, 'j5');},
getMarketCapRealtime: function(symbol){
return _request(symbol, 'j3');},
getChangeFrom52WeekHigh: function(symbol){
return _request(symbol, 'k4');},
getFloatShares: function(symbol){
return _request(symbol, 'f6');},
getPercentChangeFrom52WeekLow: function(symbol){
return _request(symbol, 'j6');},
getCompanyName: function(symbol){
return _request(symbol, 'n');},
getPercentChangeFrom52WeekHigh: function(symbol){
return _request(symbol, 'k5');},
getNotes: function(symbol){
return _request(symbol, 'n4');},
get52WeekRange: function(symbol){
return _request(symbol, 'w');},
getSharesOwned: function(symbol){
return _request(symbol, 's1');},
getStockExchange: function(symbol){
return _request(symbol, 'x');},
getSharesOutstanding: function(symbol){
return _request(symbol, 'j2');},
getVolume: function(symbol){
return _request(symbol, 'v');},
getAskSize: function(symbol){
return _request(symbol, 'a5');},
getBidSize: function(symbol){
return _request(symbol, 'b6');},
getLastTradeSize: function(symbol){
return _request(symbol, 'k3');},
getTickerTrend: function(symbol){
return _request(symbol, 't7');},
getAverageDailyVolume: function(symbol){
return _request(symbol, 'a2');},
getTradeLinks: function(symbol){
return _request(symbol, 't6');},
getOrderBookRealtime: function(symbol){
return _request(symbol, 'i5');},
getHighLimit: function(symbol){
return _request(symbol, 'l2');},
getEps: function(symbol){
return _request(symbol, 'e');},
getLowLimit: function(symbol){
return _request(symbol, 'l3');},
getEpsEstimateCurrentYear: function(symbol){
return _request(symbol, 'e7');},
getHoldingsValue: function(symbol){
return _request(symbol, 'v1');},
getEpsEstimateNextYear: function(symbol){
return _request(symbol, 'e8');},
getHoldingsValueRealtime: function(symbol){
return _request(symbol, 'v7');},
getEpsEstimateNextQuarter: function(symbol){
return _request(symbol, 'e9');},
getRevenue: function(symbol){
return _request(symbol, 's6');},
getBookValue: function(symbol){
return _request(symbol, 'b4');},
getEbitda: function(symbol){
return _request(symbol, 'j4');},
getPriceSales: function(symbol){
return _request(symbol, 'p5');},
getPriceBook: function(symbol){
return _request(symbol, 'p6');},
getPe: function(symbol){
return _request(symbol, 'r');},
getPeRealtime: function(symbol){
return _request(symbol, 'r2');},
getPeg: function(symbol){
return _request(symbol, 'r5');},
getPriceEpsEstimateCurrentYear: function(symbol){
return _request(symbol, 'r6');},
getPriceEpsEstimateNextYear: function(symbol){
return _request(symbol, 'r7');},
getShortRatio: function(symbol){
return _request(symbol, 's7');},
};
return factory;
});
angular.module("app",['ionic']).controller("mainCtrl",function($scope,yahooStock){
yahooStock.getBookValue('GOOG').then(function(response){
$scope.data = response.data;
});
});