-
Notifications
You must be signed in to change notification settings - Fork 1
/
buyer.js
79 lines (63 loc) · 1.98 KB
/
buyer.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
const gdaxWrapper = require('./modules/gdaxWrapper');
const gager = require('./modules/gager');
const config = require('./config.json');
const noise = require('./modules/noise');
const authClient = new gdaxWrapper.getAuthClient(
config.gdax.key,
config.gdax.secret,
config.gdax.passphrase,
"https://api.gdax.com"
);
const publicClient = {
"ETH-USD": gdaxWrapper.getPublicClient('ETH-USD'),
"BTC-USD": gdaxWrapper.getPublicClient('BTC-USD'),
"LTC-USD": gdaxWrapper.getPublicClient('LTC-USD'),
"ZRX-USD": gdaxWrapper.getPublicClient('ZRX-USD')
};
const productID = process.env.PRODUCT_ID || config.defaults.productId;
//biased af
const theirID = (productID == "ETH-USD") ? "BTC-USD" : "ETH-USD";
const interval = config.defaults.bottomFinderInterval;
const mustMeet = parseFloat(process.env.MM || config.defaults.bottomFinderThreshold);
const highestPoint = {
'ETH-USD': false,
'BTC-USD': false,
'LTC-USD': false,
'ZRX-USD': false
};
function debug(client, msg) {
if(client.productID == productID) {
console.log(msg);
}
}
async function findBottom(client) {
const ticker = await gdaxWrapper.getTicker(client);
const productID = client.productID;
ticker.price = parseFloat(ticker.price);
const tickerPrice = ticker.price;
debug(client, `Highest point is ${highestPoint[productID]} from ${tickerPrice}`);
if(!highestPoint[productID] || tickerPrice > highestPoint[productID]) {
highestPoint[productID] = tickerPrice;
}
if((highestPoint[productID] - tickerPrice) >= mustMeet) {
noise.soundAlarm();
}
}
const mine = publicClient[productID];
const theirs = publicClient[theirID];
findBottom(mine);
let mineGager, theirGager = false;
setInterval( () => {
findBottom(mine);
mineGager = gager.gageByClient(mine);
if(mineGager) {
gager.printByClient(mine);
if(!mineGager.sign == "sleep") {
noise.sayTicker(mineGager.last);
}
}
theirGager = gager.gageByClient(theirs);
if(theirGager) {
gager.printByClient(theirs);
}
}, interval);