Skip to content

Commit

Permalink
start using fool API and wire up caps ratings
Browse files Browse the repository at this point in the history
  • Loading branch information
cabhishek committed Nov 12, 2013
1 parent 09a6a7d commit 82fa58b
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 12 deletions.
5 changes: 3 additions & 2 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if ('development' == app.get('env')) {
swig.setDefaults({ cache: false });
}

// Routes
// Main UI routes
app.get('/', routes.index);
app.get('/stocks/add', stocks.index);
app.get('/snapshot/:symbol', snapshot.index);
Expand All @@ -38,7 +38,8 @@ app.get('/api/quotes/:symbol', content.quotes);
app.get('/api/content/:symbol', content.fool);
app.get('/api/trending/', content.trendingSymbols);
app.get('/api/tweets/:symbol', content.tweets);
app.get('/api/tweetWordCount/:symbol', content.tweetWordCount);
app.get('/api/tweetwordcount/:symbol', content.tweetWordCount);
app.get('/api/capsratings/:symbol', content.capsRatings);

app.listen(3000, function(){
console.log('Express server listening on port ' + app.get('port'));
Expand Down
21 changes: 21 additions & 0 deletions caps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

var request = require('request'),
_ = require('underscore'),
_s = require('underscore.string');

module.exports = function get_caps_ratings(symbol, fn){

var url = _s.sprintf("http://api.fool.com/caps/ws/json/Ticker/%s&apiKey=cf3d7f4bfeba0786742d5339a527af61", symbol);
console.log(url);

request({url:url, json:true}, function (error, response, contents) {

if (!error && response.statusCode == 200) {
return fn(null, contents.TickerList.Ticker.Percentile);
}
});
};




4 changes: 2 additions & 2 deletions quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ var request = require('request'),

module.exports = function get_quotes(symbol, startDate, endDate, fn){

var url = _s.sprintf("http://www.xignite.com/xGlobalHistorical.json/GetGlobalHistoricalQuotesRange?Identifier=%s&IdentifierType=Symbol&AdjustmentMethod=None&StartDate=%s&EndDate=%s&_token=f84fe133c5884b8ab4ece26c11c3000e", symbol, startDate, endDate);
var url = _s.sprintf("http://api.fool.com/quotes/tmf/v1/historical?symbols=NASDAQ:%s&startDate=%s&endDate=%s&apiKey=cf3d7f4bfeba0786742d5339a527af61", symbol, startDate, endDate);
console.log(url);

request({url:url, json:true}, function (error, response, contents) {

if (!error && response.statusCode == 200) {
return fn(null, contents.GlobalQuotes);
return fn(null, contents.chartInfos[0].historicalQuotes);
}
});
};
Expand Down
8 changes: 8 additions & 0 deletions routes/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var get_fool_content = require('../fool'),
get_trending_symbol = require('../stocktwits').get_trending_symbol,
get_tweets = require('../stocktwits').get_tweets,
get_word_counts = require('../stocktwits').get_word_counts,
get_caps_ratings = require('../caps'),
get_quotes = require('../quotes');

exports.fool = function(req, res){
Expand Down Expand Up @@ -46,3 +47,10 @@ exports.tweetWordCount = function(req, res){
res.json(contents);
});
};

exports.capsRatings = function(req, res){
get_caps_ratings(req.params.symbol, function(err, contents){

res.json(contents);
});
};
15 changes: 7 additions & 8 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@ var load_sentiments = require('../psychsignal'),
load_trending_symbols = require('../stocktwits').get_trending_symbol;

exports.index = function(req, res) {

var myStocks = ['MSFT', 'AAPL', 'GOOG', 'SBUX', 'NFLX'];
var number_of_callbacks = 3;
var final_data = [];
var model = {};
var callbackCounter = 0;

myStocks.forEach(function(stock){

var results = {};

async.waterfall([
Expand All @@ -31,7 +30,7 @@ exports.index = function(req, res) {
},
function(results, callback) {

load_quotes(stock, '2013-07-01', '2013-10-31', function(err, contents){
load_quotes(stock, '20130701', '20131031', function(err, contents){
results.quotes = contents;
callbackCounter++;
callback(null, results);
Expand All @@ -50,11 +49,11 @@ exports.index = function(req, res) {
})
}
], function(err, results){

var rows = [];

results.forEach(function(result){

var idea_count = Math.floor((Math.random() * 30) + 1);
var sentimetric = (Math.random() * 9) + 1;
var real_sentimetric = sentimetric.toFixed(2);
Expand All @@ -70,13 +69,13 @@ exports.index = function(req, res) {
for (var y = 0; y < non_caps_star_count; y++) {
non_caps_stars.push("not");
}

var row = {
"rank": 0,
"symbol": result.symbol,
"idea_num": idea_count,
"sentimetric": real_sentimetric,
"price": result.quotes[0].LastClose,
"price": result.quotes[0].close,
"cap_stars": caps_stars,
"non_cap_stars": non_caps_stars,
"bullish": result.sentiments.bullish[0].value,
Expand All @@ -96,4 +95,4 @@ exports.index = function(req, res) {
}
})
});
};
};

0 comments on commit 82fa58b

Please sign in to comment.