-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.ts
76 lines (63 loc) · 2.61 KB
/
main.ts
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
declare const global;
import * as cluster from "cluster";
import * as dotenv from "dotenv-safe";
dotenv.load();
import * as _ from "lodash";
import * as CONFIG from "./Config/CONFIG";
import BittrexMarketMakerBot from "./Engines/BittrexMarketMakerBot";
// import BittrexExchangeService from "./Services/BittrexExchangeService";
const numWorkers: number = 1; // require('os').cpus().length;
// USE MULTIPLE CORES
if (cluster.isMaster) {
console.log('Master cluster setting up ' + numWorkers + ' worker(s)...');
// const bittrexExchangeService = new BittrexExchangeService();
async function prepareWorkers() {
// get all markets
// let allMarkets = await bittrexExchangeService.getMarketSummaries();
// allMarkets = allMarkets.map((market) => {
// return {
// marketName: market.MarketName,
// spreadPercentage: ((market.Ask - market.Bid) / market.Ask) * 100,
// baseVolume: market.BaseVolume,
// };
// });
// // Keep BTC markets
// allMarkets = allMarkets.filter((market) => market.marketName.split("-")[0] === "ETH");
// // Keep spreads > 0.5%
// allMarkets = allMarkets.filter((market) => market.spreadPercentage > 0.5);
// // sort by volume
// allMarkets = allMarkets.sort((a, b) => b.baseVolume - a.baseVolume);
// // keep first ones
// allMarkets = allMarkets.slice(0, 15);
// // sort by spreadPercentage
// allMarkets = allMarkets.sort((a, b) => b.spreadPercentage - a.spreadPercentage);
// console.log(`Selected markets:\n${JSON.stringify(allMarkets)}\n`);
for (let i = 0; i < numWorkers; i++) {
const worker = cluster.fork();
worker.send({workerId: i, marketName: CONFIG.BITTREX.MARKETS_TO_MONITOR[i]});
}
}
prepareWorkers();
} else {
process.on("message", (data) => {
global.WORKER_ID = data.workerId;
global.MARKET_NAME = data.marketName;
global.CONFIG = CONFIG;
console.log(`WORKER#${data.workerId} MONITORING ${data.marketName}`);
try {
const bittrexMarketMakerBot = new BittrexMarketMakerBot(data.marketName);
bittrexMarketMakerBot.start();
} catch (err) {
console.error(err);
}
});
}
process.on("unhandledRejection", (err) => {
// Will print "unhandledRejection err is not defined"
console.error("!!!! Unhandled Rejection !!!!");
console.error(err);
});
process.on("uncaughtException", (ex) => {
console.error('!!!! Uncaught Exception thrown !!!!');
console.error(ex);
});