-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (77 loc) · 2.16 KB
/
Copy pathindex.js
File metadata and controls
93 lines (77 loc) · 2.16 KB
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
83
84
85
86
87
88
89
90
91
92
93
const Twit = require('twit');
const names = require('./names.js');
const Poloniex = require('poloniex-api-node');
const API_KEY = '';
const SECRET = '';
let poloniex = new Poloniex(API_KEY, SECRET);
var IDChecked = [];
var CoinsDetected = [];
const safeCheck = true; //HIGHLY recomended~~!
const buyAmount = 0; //Amount must be at least 0.000001. This value in BTC
const T = new Twit({
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
});
var stream = T.stream('statuses/filter', { follow : '961445378' });
stream.on('tweet', (tweet, err) => {
if (!isIn(tweet.id)) {
checkTweet(tweet.text);
} else {
console.log(`Found tweet ${tweet.id} but it has already been processed`);
}
})
function checkTweet(text){
text = text.toLowerCase();
if (safeCheck) {
for (var val of names) {
if (text.includes(val.toLowerCase()) && text.toLowerCase().includes('coin of the day')) {
checkBalancesandBuy(val.toUpperCase());
}
}
} else {
for (var val of names) {
if (text.includes(val)) {
checkBalancesandBuy(val.toUpperCase());
}
}
}
}
function isIn(id) {
for (var val of IDChecked) {
if (val === id) {
return true;
}
}
IDChecked.push(id);
return false;
}
function checkBalancesandBuy(val) {
poloniex.returnBalances((err, balance) => {
if (err) throw err;
if (balance.BTC >= buyAmount) {
const currencyPair = `BTC_${val}`;
poloniex.returnOrderBook(currencyPair, 1, (err, result) => {
if (err) throw err;
let buyPrice = result.asks[0][0]; //might want to increase by a fraction of a percent.
buy(buyPrice, currencyPair);
})
}
})
}
function buy(buyprice, currencyPair) {
//buy(currencyPair, rate, amount, fillOrKill, immediateOrCancel, postOnly [, callback]) ; feel free to change settings to make it safer
const amount = buyAmount / buyprice;
poloniex.buy(currencyPair, buyprice, amount, false, false, false, (err, result) => {
if (err) {
console.log(err);
} else {
console.log(`MADE PURCHASE ${result}`);
}
});
}
/* test
let a = 'zec coin of the day';
checkTweet(a);
*/