forked from Adamant-im/adamant-tradebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
47 lines (41 loc) · 1.55 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
const notify = require('./helpers/notify');
const db = require('./modules/DB');
const doClearDB = process.argv.includes('clear_db');
const config = require('./modules/configReader');
const { initApi } = require('./routes/init');
// 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 });
}
setTimeout(init, 5000);
function init() {
try {
if (config.api?.port) {
initApi();
}
if (doClearDB) {
console.log('Clearing database…');
db.systemDb.db.drop();
db.incomingTxsDb.db.drop();
db.ordersDb.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/mm_trader').run();
require('./trade/mm_orderbook_builder').run();
require('./trade/mm_liquidity_provider').run();
require('./trade/mm_price_watcher').run();
// require('./trade/mm_orderbook_builder').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) {
notify(`${config.notifyName} is not started. Error: ${e}`, 'error');
process.exit(1);
}
}