Socket
Socket
Sign inDemoInstall

hubot-stock-checker

Package Overview
Dependencies
1
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.6.4 to 2.0.0

src/urlBuilder.js

8

package.json
{
"name": "hubot-stock-checker",
"version": "1.6.4",
"description": "Hubot script to interact with IEX stock exchange apis. Provides stock quotes, company stats, company info and dividend history. Allows users and channels to manage watchlists of favorite stocks, check value of saved holdings, and provides quick access to the IEX top movers, losers, and winners collections.",
"version": "2.0.0",
"description": "Hubot script to interact with the IEX Cloud stock exchange apis. Provides stock quotes, company stats, company info and dividend history. Allows users and channels to manage watchlists of favorite stocks, check value of saved holdings, and provides quick access to the IEX top movers, losers, and winners collections. Requires an IEX Cloud api key.",
"main": "index.js",

@@ -16,3 +16,5 @@ "repository": {

"hubot-stock-checker",
"hubot-scripts"
"hubot-scripts",
"iex cloud",
"iex-cloud"
],

@@ -19,0 +21,0 @@ "author": "Kyle Andrews <https://github.com/kwandrews7>",

@@ -5,5 +5,5 @@ Get quick stats on any stock by asking your hubot!

This integration utilizes hubot to interact with stock stats provided for free by [IEX Trading](https://iextrading.com/developer). I wanted quick access via my bot to stock updates and realized that the existing hubot options were old and broken; most relying on the deprecated Yahoo! Finance APIs. Many thanks to IEX Trading for providing a reliable, free, and easy to use API. It made this process super easy.
This integration utilizes hubot to interact with stock stats provided by [IEX Cloud](https://iexcloud.io/). I wanted quick access via my bot to stock values and found many existing hubot options were broken. So, I chose to write my own interacting with the free IEX Trading API. As of v2, IEX has moved away from the original IEX Trading api's to a new IEX Cloud api. You will need an IEX Cloud token (api key) to utilize this hubot plugin. Please note that these tokens are free, but paid tiers based on usage do exists.
Since the start of this script, I've been adding features at a pretty good clip to fulfill the of those in our Slack team. However, if you have a feature you want, catch me on twitter (@kwandrews7) or create a pull request. Their API docs are linked above, check it out to see everything available.
Since the start of this script, I've added a handful of features to fulfill the needs of me and my friends. However, if you have a feature you want, catch me on twitter (@kwandrews7) or create a pull request. [API docs are linked are available here.](https://iexcloud.io/docs/api/)

@@ -57,5 +57,14 @@ Example Interaction:

["hubot-stock-checker"]
Once installed, you will need to configure your IEX Cloud public token as environment variable `HUBOT_IEX_CLOUD_TOKEN`.
## Release Notes
### 2.0.0
* All calls updated to use the new IEX Cloud apis.
* Script now requires configuration of IEX Cloud api token environment variable.
* Readme updated with latest links and information related to IEX Cloud.
* All urls moved into urlBuilder.js to consolidate the use of the token param.
### 1.6.4

@@ -62,0 +71,0 @@

const numeral = require('numeral');
const iexBaseUrl = 'https://api.iextrading.com/1.0';
const iexBaseUrl = 'https://cloud.iexapis.com/v1';
const {

@@ -10,2 +10,3 @@ mny,

} = require('./formatters');
const urlBuilder = require('./urlBuilder');

@@ -15,4 +16,8 @@ module.exports = function (robot) {

robot.respond(/(get )?stock (\w*\.?\w*)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
robot.logger.debug(`hubot-stock-checker: getStock [${msg.match[2]}] called`);
let statsUrl = `${iexBaseUrl}/stock/${msg.match[2]}/quote`;
let statsUrl = urlBuilder.quote(msg.match[2]);
msg.http(statsUrl).get()(function (err, res, body) {

@@ -29,4 +34,8 @@ if (res.statusCode >= 400) {

robot.respond(/(get )?stock (\w*\.?\w*) (div|dividend|divs|dividends)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
robot.logger.debug(`hubot-stock-checker: getStockDividends [${msg.match[2]}] called`);
let divsUrl = `${iexBaseUrl}/stock/${msg.match[2]}/dividends/1y`;
let divsUrl = urlBuilder.dividends(msg.match[2]);
msg.http(divsUrl).get()(function (err, res, body) {

@@ -46,4 +55,8 @@ if (res.statusCode >= 400) {

robot.respond(/(get )?stock (\w*\.?\w*) (info)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
robot.logger.debug(`hubot-stock-checker: getStockInfo [${msg.match[2]}] called`);
const infoUrl = `${iexBaseUrl}/stock/${msg.match[2]}/company`;
const infoUrl = urlBuilder.company(msg.match[2]);
msg.http(infoUrl).get()(function (err, res, body) {

@@ -68,4 +81,8 @@ if (res.statusCode >= 400) {

robot.respond(/(get )?stock (\w*\.?\w*) (stats|stat|statistics)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
robot.logger.debug(`hubot-stock-checker: getStockStats [${msg.match[2]}] called`);
let statsUrl = `${iexBaseUrl}/stock/${msg.match[2]}/stats`;
let statsUrl = urlBuilder.stats(msg.match[2]);
msg.http(statsUrl).get()(function (err, res, body) {

@@ -88,4 +105,8 @@ if (res.statusCode >= 400) {

robot.respond(/(get )?stock (\w*\.?\w*) (news|stories)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
robot.logger.debug(`hubot-stock-checker: getNews [${msg.match[2]}] called`);
const newsUrl = `${iexBaseUrl}/stock/${msg.match[2]}/news`;
const newsUrl = urlBuilder.news(msg.match[2]);
msg.http(newsUrl).get()(function (err, res, body) {

@@ -92,0 +113,0 @@ if (res.statusCode >= 400) {

@@ -6,2 +6,3 @@ const numeral = require('numeral');

} = require('./formatters');
const urlBuilder = require('./urlBuilder.js');

@@ -15,2 +16,6 @@ module.exports = function (robot) {

robot.respond(/save stock (\w*\.?\w*)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
let symbol = msg.match[1].toUpperCase();

@@ -33,2 +38,6 @@ let channel = msg.message.room;

robot.respond(/delete stock (\w*\.?\w*)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
let symbol = msg.match[1].toUpperCase();

@@ -38,3 +47,3 @@ let channel = msg.message.room;

if (Array.isArray(robot.brain.data.stock_checker_favs[channel]) && robot.brain.data.stock_checker_favs[channel].includes(symbol)) {
if (Array.isArray(robot.brain.data.stock_checker_favs[channel]) && robot.brain.data.stock_checker_favs[channel].includes(symbol)) {
robot.brain.data.stock_checker_favs[channel] = robot.brain.data.stock_checker_favs[channel]

@@ -49,2 +58,6 @@ .filter(_symbol => _symbol.toUpperCase() !== symbol.toUpperCase());

robot.respond(/(list )?(my |our )?favorites?( stocks)?$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
let symbol = msg.match[1].toUpperCase();

@@ -56,3 +69,3 @@ let channel = msg.message.room;

robot.brain.data.stock_checker_favs[channel].forEach(function (fav) {
let stockUrl = `${iexBaseUrl}/stock/${fav}/quote`;
let stockUrl = urlBuilder.quote(fav);
msg.http(stockUrl).get()(function (err, res, body) {

@@ -59,0 +72,0 @@ if (res.statusCode >= 400) {

@@ -6,2 +6,3 @@ const numeral = require('numeral');

} = require('./formatters');
const urlBuilder = require('./urlBuilder.js');

@@ -15,2 +16,6 @@ module.exports = function (robot) {

robot.respond(/save (\d+) shares of (\w*\.?\w*)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
let numShares = parseFloat(msg.match[1]);

@@ -28,2 +33,6 @@ let symbol = msg.match[2].toUpperCase();

robot.respond(/delete shares of (\w*\.?\w*)$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
let numShares = parseFloat(msg.match[1]);

@@ -41,2 +50,6 @@ let symbol = msg.match[1].toUpperCase();

robot.respond(/(list )?(my |our )?holdings( )?$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
let numShares = msg.match[1];

@@ -65,3 +78,3 @@ let symbol = msg.match[2].toUpperCase();

function getHoldings(msg, symbol, numShares) {
let stockUrl = `${iexBaseUrl}/stock/${symbol}/quote`;
let stockUrl = urlBuilder.quote(symbol);
msg.http(stockUrl).get()(function (err, res, body) {

@@ -68,0 +81,0 @@ if (res.statusCode >= 400) {

@@ -6,2 +6,3 @@ const numeral = require('numeral');

} = require('./formatters');
const urlBuilder = require('./urlBuilder.js');

@@ -11,4 +12,8 @@ module.exports = function (robot) {

robot.respond(/(get )?stock top losers$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
robot.logger.debug(`hubot-stock-checker: getTopLosers called`);
let losersUrl = `${iexBaseUrl}/stock/market/list/losers`;
let losersUrl = urlBuilder.marketLosers();
msg.http(losersUrl).get()(function (err, res, body) {

@@ -21,4 +26,8 @@ let losers = JSON.parse(body).slice(0, 5).map(x => simpleStockSummary(x)).join('\n');

robot.respond(/(get )?stock top winners$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
robot.logger.debug(`hubot-stock-checker: getTopWinners called`);
let gainersUrl = `${iexBaseUrl}/stock/market/list/gainers`;
let gainersUrl = urlBuilder.marketWinners();
msg.http(gainersUrl).get()(function (err, res, body) {

@@ -31,4 +40,8 @@ const winners = JSON.parse(body).slice(0, 5).map(x => simpleStockSummary(x)).join('\n');

robot.respond(/(get )?stock top movers$/i, function (msg) {
if (urlBuilder.failIfMissingToken(msg)) {
return;
}
robot.logger.debug(`hubot-stock-checker: getTopMovers called`);
let moversUrl = `${iexBaseUrl}/stock/market/list/mostactive`;
let moversUrl = urlBuilder.marketMovers();
msg.http(moversUrl).get()(function (err, res, body) {

@@ -35,0 +48,0 @@ let movers = JSON.parse(body).slice(0, 5).map(x => simpleStockSummary(x)).join('\n');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc