Skip to content

Commit 2ca5248

Browse files
Tyler Johnsonaskmike
authored andcommitted
1 parent 4477ff3 commit 2ca5248

File tree

3 files changed

+103
-0
lines changed

3 files changed

+103
-0
lines changed

plugins.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ var plugins = [
177177
async: false,
178178
modes: ['realtime']
179179
},
180+
{
181+
name: 'IFTTT',
182+
description: 'Sends trades to IFTTTT webhook.',
183+
slug: 'ifttt',
184+
async: false,
185+
modes: ['realtime']
186+
}
180187
];
181188

182189
module.exports = plugins;

plugins/ifttt.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
const superagent = require('superagent');
2+
const _ = require('lodash');
3+
const log = require('../core/log.js');
4+
const util = require('../core/util.js');
5+
const config = util.getConfig();
6+
const iftttConfig = config.ifttt;
7+
8+
const IFTTT = function(done) {
9+
_.bindAll(this);
10+
this.ifttt;
11+
this.price = 'N/A';
12+
this.done = done;
13+
this.setup();
14+
};
15+
16+
IFTTT.prototype.setup = function(done) {
17+
var setupIFTTT = function () {
18+
if(iftttConfig.sendMessageOnStart){
19+
var exchange = config.watch.exchange;
20+
var currency = config.watch.currency;
21+
var asset = config.watch.asset;
22+
var body = "Gekko has started, Ive started watching "
23+
+exchange
24+
+" "
25+
+currency
26+
+" "
27+
+asset
28+
+" I'll let you know when I got some advice";
29+
this.send(body);
30+
}else{
31+
log.debug('Skipping Send message on startup')
32+
}
33+
};
34+
setupIFTTT.call(this)
35+
};
36+
37+
IFTTT.prototype.processCandle = function(candle, done) {
38+
this.price = candle.close;
39+
40+
done();
41+
};
42+
43+
IFTTT.prototype.portfolioUpdate = function(portfolio) {
44+
var message = "Gekko has detected a portfolio update. " +
45+
"Your current " + config.watch.currency + " balance is " + portfolio.currency + '.' +
46+
"Your current " + config.watch.exchange + " balance is " + portfolio.assert + '.';
47+
this.send(message);
48+
}
49+
50+
IFTTT.prototype.processAdvice = function(advice) {
51+
if (advice.recommendation == 'soft' && iftttConfig.muteSoft) return;
52+
53+
const text = [
54+
'Gekko is watching ',
55+
config.watch.exchange,
56+
' and has detected a new trend, advice is to go ',
57+
advice.recommendation,
58+
'.\n\nThe current ',
59+
config.watch.asset,
60+
' price is ',
61+
this.price
62+
].join('');
63+
64+
this.send(text);
65+
};
66+
67+
IFTTT.prototype.send = function(content) {
68+
superagent.
69+
post('https://maker.ifttt.com/trigger/' + iftttConfig.eventName + '/with/key/' + iftttConfig.makerKey)
70+
.send({value1: content})
71+
.end(function(err, res){
72+
if(err || !res){
73+
log.error('IFTTT ERROR:', error)
74+
}else{
75+
log.info('IFTTT Message Sent')
76+
}
77+
});
78+
};
79+
80+
IFTTT.prototype.checkResults = function(error) {
81+
if (error) {
82+
log.warn('error sending IFTTT', error);
83+
} else {
84+
log.info('Send advice via IFTTT.');
85+
}
86+
};
87+
88+
module.exports = IFTTT;

sample-config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,14 @@ config.slack = {
369369
channel: '' // #tradebot
370370
}
371371

372+
config.ifttt = {
373+
enabled: false,
374+
eventName: 'gekko',
375+
makerKey: '',
376+
muteSoft: true,
377+
sendMessageOnStart: true
378+
}
379+
372380
config.candleWriter = {
373381
enabled: false
374382
}

0 commit comments

Comments
 (0)