Skip to content

Instantly share code, notes, and snippets.

@jasonmcleod
Created June 19, 2013 14:57
Show Gist options
  • Select an option

  • Save jasonmcleod/5814979 to your computer and use it in GitHub Desktop.

Select an option

Save jasonmcleod/5814979 to your computer and use it in GitHub Desktop.
app.factory('trendingStocks', function($http) {
return {
fetch:function() {
var promise = $http.jsonp('https://api.stocktwits.com/api/2/streams/trending.json?callback=JSON_CALLBACK').then(function (response) {
var exp = /(\$[A-Z]{1,5})/;
var tweets = response.data.messages;
var trending = [];
for(var t in tweets) {
var symbols = exp.exec(tweets[t].body)
for(var s in symbols) {
if(!isNaN(s)) trending.push(symbols[s].replace('$',''));
}
}
trending = _.unique(trending);
return trending
});
return promise
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment