forked from askmike/gekko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.js
82 lines (70 loc) · 2.16 KB
/
twitter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var _ = require('lodash');
var log = require('../core/log.js');
var util = require('../core/util.js');
var config = util.getConfig();
var twitterConfig = config.twitter;
var TwitterApi = require('twitter');
require('dotenv').config()
var Twitter = function(done) {
_.bindAll(this);
this.twitter;
this.price = 'N/A';
this.done = done;
this.setup();
};
Twitter.prototype.setup = function(done){
var setupTwitter = function (err, result) {
this.client = new TwitterApi({
consumer_key: config.consumer_key,
consumer_secret: config.consumer_secret,
access_token_key: config.access_token_key,
access_token_secret: config.access_token_secret
});
if(twitterConfig.sendMessageOnStart){
var exchange = config.watch.exchange;
var currency = config.watch.currency;
var asset = config.watch.asset;
var body = "Watching "
+exchange
+" "
+currency
+" "
+asset
this.mail(body);
}else{
log.debug('Skipping Send message on startup')
}
};
setupTwitter.call(this)
};
Twitter.prototype.processCandle = function(candle, done) {
this.price = candle.close;
done();
};
Twitter.prototype.processAdvice = function(advice) {
if (advice.recommendation == "soft" && twitterConfig.muteSoft) return;
var text = [
'New #ethereum trend. Attempting to ',
advice.recommendation == "short" ? "sell" : "buy",
' @',
this.price,
].join('');
this.mail(text);
};
Twitter.prototype.mail = function(content, done) {
log.info("trying to tweet");
this.client.post('statuses/update', {status: content}, function(error, tweet, response) {
if(error || !response) {
log.error('Pushbullet ERROR:', error)
} else if(response && response.active){
log.info('Pushbullet Message Sent')
}
});
};
Twitter.prototype.checkResults = function(err) {
if(err)
log.warn('error sending email', err);
else
log.info('Send advice via email.');
};
module.exports = Twitter;