Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Added send/buy orders notifications using Slack's Incoming WebHooks API. #583

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions conf-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ c.balance_snapshot_period = '15m'
// avg. amount of slippage to apply to sim trades
c.avg_slippage_pct = 0.045

// send updates via slack webhook
// https://api.slack.com/incoming-webhooks
c.slack_enable = false
c.slack_webhook_url = ''

//xmpp configs

c.xmppon=0 // 0 xmpp disabled; 1 xmpp enabled (credentials should be correct)
Expand Down
3 changes: 2 additions & 1 deletion lib/_codemap.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ module.exports = {
'rsi': require('./rsi'),
'sma': require('./sma'),
'srsi': require('./srsi'),
'stddev': require('./stddev')
'stddev': require('./stddev'),
'slack': require('./slack')
}
12 changes: 10 additions & 2 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,12 @@ module.exports = function container (get, set, clear) {
order_type: so.order_type
}
s.my_trades.push(my_trade)
var body = '\nbuy order completed at ' + moment(trade.time).format('YYYY-MM-DD HH:mm:ss') + ':\n\n' + fa(my_trade.size) + ' at ' + fc(my_trade.price) + '\ntotal ' + fc(my_trade.size * my_trade.price) + '\n' + n(my_trade.slippage).format('0.0000%') + ' slippage (orig. price ' + fc(s.buy_order.orig_price) + ')\nexecution: ' + moment.duration(my_trade.execution_time).humanize() + '\n'
if (so.stats) {
console.log(('\nbuy order completed at ' + moment(trade.time).format('YYYY-MM-DD HH:mm:ss') + ':\n\n' + fa(my_trade.size) + ' at ' + fc(my_trade.price) + '\ntotal ' + fc(my_trade.size * my_trade.price) + '\n' + n(my_trade.slippage).format('0.0000%') + ' slippage (orig. price ' + fc(s.buy_order.orig_price) + ')\nexecution: ' + moment.duration(my_trade.execution_time).humanize() + '\n').cyan)
console.log(body.cyan)
}
if (c.slack_enable) {
get('lib.slack')(c, body)
}
s.last_buy_price = my_trade.price
delete s.buy_order
Expand Down Expand Up @@ -613,8 +617,12 @@ module.exports = function container (get, set, clear) {
order_type: so.order_type
}
s.my_trades.push(my_trade)
var body = '\nsell order completed at ' + moment(trade.time).format('YYYY-MM-DD HH:mm:ss') + ':\n\n' + fa(my_trade.size) + ' at ' + fc(my_trade.price) + '\ntotal ' + fc(my_trade.size * my_trade.price) + '\n' + n(my_trade.slippage).format('0.0000%') + ' slippage (orig. price ' + fc(s.sell_order.orig_price) + ')\nexecution: ' + moment.duration(my_trade.execution_time).humanize() + '\n';
if (so.stats) {
console.log(('\nsell order completed at ' + moment(trade.time).format('YYYY-MM-DD HH:mm:ss') + ':\n\n' + fa(my_trade.size) + ' at ' + fc(my_trade.price) + '\ntotal ' + fc(my_trade.size * my_trade.price) + '\n' + n(my_trade.slippage).format('0.0000%') + ' slippage (orig. price ' + fc(s.sell_order.orig_price) + ')\nexecution: ' + moment.duration(my_trade.execution_time).humanize() + '\n').cyan)
console.log(body.cyan)
}
if (c.slack_enable) {
get('lib.slack')(c, body)
}
s.last_sell_price = my_trade.price
delete s.sell_order
Expand Down
16 changes: 16 additions & 0 deletions lib/slack.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var IncomingWebhook = require('@slack/client').IncomingWebhook;

module.exports = function container (get, set, clear) {
return function slack (c, body) {
var slackWebhook = new IncomingWebhook(c.slack_webhook_url || '');

slackWebhook.send(body, function (err, header, statusCode, body) {
if (err) {
console.error('\nerror: slack webhook')
console.error(err)
} else {
console.log('\nslack webhook statusCode = ', statusCode)
}
});
}
}
111 changes: 111 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"zenbot": "./zenbot.sh"
},
"dependencies": {
"@slack/client": "^3.14.0",
"async": "^2.5.0",
"bitfinex-api-node": "^1.2.0",
"bitstamp": "^1.0.4",
Expand Down