-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathapp.js
71 lines (60 loc) · 2.14 KB
/
app.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
const config = require('./modules/configReader');
const db = require('./modules/DB');
// It may take up to a second to create trading params file 'tradeParams_{exchange}.js' from the default one
setTimeout(initServices, 1000);
// It may take up to a 5 seconds to get exchange markets and Infoservice rates
setTimeout(startModules, 5000);
function initServices() {
try {
// Socket connection
if (config.passPhrase) {
const api = require('./modules/api');
const txParser = require('./modules/incomingTxsParser');
if (config.socket) {
api.initSocket({ wsType: config.ws_type, admAddress: config.address });
api.socket.on(txParser);
}
}
// Debug and health API init
const { initApi } = require('./routes/init');
if (config.api?.port) {
initApi();
}
} catch (e) {
console.error(`${config.notifyName} is not started. Error: ${e}`);
process.exit(1);
}
}
function startModules() {
try {
const notify = require('./helpers/notify');
if (config.doClearDB) {
console.log(`${config.notifyName}: Clearing database…`);
db.systemDb.db.drop();
db.incomingTxsDb.db.drop();
db.incomingTgTxsDb.db.drop();
db.incomingCLITxsDb.db.drop();
db.ordersDb.db.drop();
db.fillsDb.db.drop();
db.webTerminalMessages.drop();
console.log(`${config.notifyName}: Database cleared. Manually stop the Bot now.`);
} else {
if (config.passPhrase) {
const checker = require('./modules/checkerTransactions');
checker();
}
require('./trade/mm_trader').run();
require('./trade/mm_orderbook_builder').run();
require('./trade/mm_liquidity_provider').run();
require('./trade/mm_price_watcher').run();
if (config.dev) {
require('./trade/tests/manual.test').run();
}
const addressInfo = config.address ? ` for address _${config.address}_` : ' in CLI mode';
notify(`${config.notifyName} *started*${addressInfo} (${config.projectBranch}, v${config.version}).`, 'info');
}
} catch (e) {
console.error(`${config.notifyName} is not started. Error: ${e}`);
process.exit(1);
}
}