-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
127 lines (103 loc) · 3.67 KB
/
main.js
File metadata and controls
127 lines (103 loc) · 3.67 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// add timestamps in front of log messages
require('console-stamp')(console, 'yyyy-mm-dd HH:MM:ss');
const graphite = require('graphite');
const config = require('./config');
const grphClient = graphite.createClient(config.graphiteUrl);
const VERSION = "2_5";
const isProduction = process.env.PRODUCTION==1;
const COUNTER_PREFIX = `walletProfileBot.${VERSION}.${isProduction? 'production':'debug'}`;
const inflx = require("./influx")({
app:"walletProfileBot",
version:VERSION,
build:isProduction? 'production':'debug'
});
const counter = require("./counter")(grphClient, inflx, COUNTER_PREFIX);
const Monitor = require("./monitor");
// upodate every 3cd /opt/graphite/confh - don ttl=6
//const wallets = require("./wallets")(Monitor(1000 * 60 * 60 * 3), counter);
const wallets = require("./wallets")(counter, config);
//fast
//const wallets = require("./wallets")(Monitor(1000 * 60 * 1));
const tokens = require("./tokens")(COUNTER_PREFIX, Monitor(1000 * 60 * 5), wallets, counter);
const swaps = require("./swaps")(Monitor(1000 * 60 * 5), tokens, counter);
// fast const swaps = require("./swaps")(Monitor(1000 * 30), tokens);
// const tradeRoom = require("./trader")(Monitor(1000 * 60 * 5));
// tradeRoom.load('traderoom.json');
///////////////////////////////////////////////////////
// monitoring
async function next(){
try {
// update
//console.log("+++ +++ +++ interval")
await swaps.update();
await tokens.update();
//send wallet status distribution metrics
// before updating expired
wallets.status(true);
// update wallet - NON blocking, takes ages
/*await*/ wallets.update();
// send metrics
tokens.sendMetrics(grphClient, inflx);
// update traders - and send metrics
//tradeRoom.update(tokens.data, grphClient);
// starts and errors
counter.sendMetrics();
}
catch(e){
counter.addError('main.exception');
console.error(e);
}
// 1 min production - 0.5 min debug
setTimeout(next, 1000 * (isProduction? 60 : 30 ));
}
///////////////////////////////////////////////////////
async function loadCache(){
await tokens.load();
}
///////////////////////////////////////////////////////
if (require.main === module) {
console.log("============== ORBS WALLET PROFILE BOT ==============");
console.log("VERSION", VERSION);
console.log("WEB3_PROVIDER", config.network.ETH);
console.log("GRAPHITE", config.graphiteUrl);
console.log("INFLUX_URL", config.influxUrl);
console.log("INFLUX_BUCKET", config.influxBucket);
console.log("MAX_TOKEN_MON", config.maxToken );
console.log("WALLET_TIMEOUT_MS", config.walletTimeoutMS );
console.log("WALLET_SEC_TTL", config.walletSecondsTTL );
//console.log("WALLET_BATCH_SIZE", process.env.WALLET_BATCH_SIZE);
console.log("MEGA_HOLDER_BTC", config.megaHolderBTC);
console.log("=========================================");
//console.log(JSON.stringify(monkey1.options, null,2));
// anotation
counter.addStat("process.started");
// load cache
loadCache();
// start iteration
next();
// start server
const express = require('express');
const app = express();
const port = 3001;
app.get('/', (req, res) => {
res.send('wallet-profile-bot OK!');
})
app.get('/token', (req, res) => {
res.json(tokens.asJson());
})
// app.get('/wallet', (req, res) => {
// res.send(`
// ${wallets.size()} are being monitored
// ${wallets.notUpdated()} are notUpdated
// `);
// })
app.get('/wallet/dump', (req, res) => {
res.json(wallets.data);
})
app.get('/wallet', (req, res) => {
res.json(wallets.status());
})
app.listen(port, () => {
console.log(`Example app listening at http://0.0.0.0:${port}`);
})
}