-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
app.js
67 lines (56 loc) · 2.04 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
const config = require('./modules/config/reader');
const db = require('./modules/DB');
const doClearDB = process.argv.includes('clear_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');
api.socket.initSocket({ socket: config.socket, wsType: config.ws_type, onNewMessage: txParser, admAddress: config.address });
}
// Debug and health API init
const { initApi } = require('./routes/init');
if (config.api?.port) {
initApi();
}
// Comserver init
const { botInterchange } = require('./modules/botInterchange');
if (config.com_server) {
botInterchange.connect();
botInterchange.initHandlers();
}
} catch (e) {
console.error(`${config.notifyName} is not started. Error: ${e}`);
process.exit(1);
}
}
function startModules() {
try {
const notify = require('./helpers/notify');
if (doClearDB) {
console.log('Clearing database…');
db.systemDb.db.drop();
db.incomingTxsDb.db.drop();
db.ordersDb.db.drop();
db.fillsDb.db.drop();
notify(`*${config.notifyName}: database cleared*. Manually stop the Bot now.`, 'info');
} else {
if (config.passPhrase) {
const checker = require('./modules/checkerTransactions');
checker();
}
require('./trade/co_ladder').run();
require('./trade/co_test').test();
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);
}
}