From 2417a8656c2c20c02a4e97aafff156c58485086e Mon Sep 17 00:00:00 2001 From: piedrogenius Date: Fri, 28 Jul 2017 12:26:43 +0200 Subject: [PATCH] xmpp for trading alarms (#333) * use of xmpp * xmpp configs * Update conf-sample.js * Update engine.js --- conf-sample.js | 20 ++++++++++++++++++++ lib/engine.js | 8 ++++++++ 2 files changed, 28 insertions(+) diff --git a/conf-sample.js b/conf-sample.js index 0a23703c54..0a6240f03d 100644 --- a/conf-sample.js +++ b/conf-sample.js @@ -124,3 +124,23 @@ c.rsi_periods = 14 c.balance_snapshot_period = '15m' // avg. amount of slippage to apply to sim trades c.avg_slippage_pct = 0.045 + +//xmpp configs + +c.xmppon=0 // 0 xmpp disabled; 1 xmpp enabled (credentials should be correct) + +if (c.xmppon) { + + c.xmpp = require('simple-xmpp'); + + c.xmpp.connect({ + jid : 'trader@domain.com', //xmpp account trader bot + password : 'Password', //xmpp password + host : 'domain.com', //xmpp domain + port : 5222 //xmpp port + }); + + c.xmppto="MeMyselfAndI@domain.com" //xmpp alert to friend +} +//end xmpp configs + diff --git a/lib/engine.js b/lib/engine.js index 17231556d7..ec672bfb45 100644 --- a/lib/engine.js +++ b/lib/engine.js @@ -182,6 +182,9 @@ module.exports = function container (get, set, clear) { if (err) return cb(err) s.start_price = n(quote.ask).value() s.start_capital = n(s.balance.currency).add(n(s.balance.asset).multiply(quote.ask)).value() + + if (c.xmppon) c.xmpp.send(c.xmppto,'Balance: ' + s.start_capital + '\n') // xmpp + cb() }) } @@ -427,6 +430,9 @@ module.exports = function container (get, set, clear) { } else { //console.log('\nplacing buy order at ' + fc(price) + ', ' + fc(quote.bid - Number(price)) + ' under best bid\n') + + if (c.xmppon) c.xmpp.send(c.xmppto,'placing buy order at ' + fc(price) + ', ' + fc(quote.bid - Number(price)) + ' under best bid\n') + doOrder() } } @@ -468,6 +474,8 @@ module.exports = function container (get, set, clear) { } else { //console.log('\nplacing sell order at ' + fc(price) + ', ' + fc(Number(price) - quote.bid) + ' over best ask\n') + if (c.xmppon) c.xmpp.send(c.xmppto,'placing sell order at ' + fc(price) + ', ' + fc(Number(price) - quote.bid) + ' over best ask\n') + doOrder() } }