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

Integration of IFTTT and PushBullet web services for notifying buy/sell operations #593

Closed
wants to merge 2 commits 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
25 changes: 24 additions & 1 deletion conf-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,12 @@ c.balance_snapshot_period = '15m'
// avg. amount of slippage to apply to sim trades
c.avg_slippage_pct = 0.045

//xmpp configs
//console configs
c.console = {}
c.console.on = 0 // console disabled; 1 console enabled
//end console configs

//xmpp configs
c.xmppon=0 // 0 xmpp disabled; 1 xmpp enabled (credentials should be correct)

if (c.xmppon) {
Expand All @@ -153,3 +157,22 @@ if (c.xmppon) {
}
//end xmpp configs

//pushbullets configs
c.pushbullet = {}
c.pushbullet.on = 0 // pushbullets disabled; 1 pushbullets enabled (key should be correct)
c.pushbullet.key = 'YOUR-API-KEY'
c.pushbullet.deviceID = 'YOUR-DEVICE-ID'

if (c.pushbullet.on) {
var pushobj = require('pushbullet');

c.pushbullet.pusher = new pushobj(c.pushbullet.key);
}
//end pushbullets configs

//ifttt configs
c.ifttt = {}
c.ifttt.on = 0 // ifttt disabled; 1 ifttt enabled (key should be correct)
c.ifttt.makerKey = 'YOUR-API-KEY'
c.ifttt.eventName = 'zenbot'
//end ifttt configs
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'),
'notify': require('./notify')
}
10 changes: 4 additions & 6 deletions lib/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var nice_errors = new RegExp(/(slippage protection|loss protection)/)

module.exports = function container (get, set, clear) {
var c = get('conf')
var notify = get('lib.notify')
return function (s) {
var so = s.options
s.selector = get('lib.normalize-selector')(so.selector)
Expand Down Expand Up @@ -183,7 +184,7 @@ module.exports = function container (get, set, clear) {
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
notify.pushMessage('Balance', 'sync balance ' + s.start_capital + '\n')

cb()
})
Expand Down Expand Up @@ -434,9 +435,7 @@ module.exports = function container (get, set, clear) {
}, c.wait_for_settlement)
}
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')
notify.pushMessage('Buy', 'placing buy order at ' + fc(price) + ', ' + fc(quote.bid - Number(price)) + ' under best bid\n')

doOrder()
}
Expand Down Expand Up @@ -478,8 +477,7 @@ module.exports = function container (get, set, clear) {
}, c.wait_for_settlement)
}
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')
notify.pushMessage('Sell', 'placing sell order at ' + fc(price) + ', ' + fc(Number(price) - quote.bid) + ' over best ask\n')

doOrder()
}
Expand Down
55 changes: 55 additions & 0 deletions lib/notify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var pb = require('pushbullet')
, https = require('https')
, request = require('request')

function sendIFTTT (eventName, makerKey, title, message) {
var postData = { "value1": title , "value2": message , "value3": "TEST2" };

function callback(error, response, body) {
if (!error) {
var info = JSON.parse(JSON.stringify(body));
console.log(info);
}
else {
console.log('Error happened: '+ error);
}
}

var options = {
method: 'POST',
url: 'https://maker.ifttt.com/trigger/' + eventName + '/with/key/' + makerKey,
json: postData
}

request(options, callback)
}

module.exports = function container (get, set, clear) {
var c = get('conf')

return {
pushMessage: function (title, message) {
if (c.console.on) {
console.log(title + ': ' + message)
}

if (c.xmppon) {
c.xmpp.send(c.xmppto, title + ': ' + message)
}

if (c.pushbullet.on) {
c.pushbullet.pusher.note(c.pushbullet.deviceID, title, message, (err, res) => {
if (err) {
console.log('error: Push message failed, ' + err)
return;
}
console.log('info: Push message result, ' + res)
});
}

if (c.ifttt.on) {
sendIFTTT(c.ifttt.eventName, c.ifttt.makerKey, title, message)
}
}
}
}
Loading