forked from tiagosiebler/TriangularArbitrage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
89 lines (76 loc) · 2.72 KB
/
index.js
File metadata and controls
89 lines (76 loc) · 2.72 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
// load logger library
const logger = require('./lib/LoggerCore');
var env = require('node-env-file');
env(__dirname + '/.keys');
env(__dirname + '/conf.ini');
if (!process.env.binance_key || !process.env.binance_secret) {
throw 'Error: Specify your binance API settings in a file called ".keys". The .keys-template can be used as a template for how the .keys file should look.';
}
logger.info('\n\n\n----- Bot Starting : -----\n\n\n');
var exchangeAPI = {};
logger.info('--- Loading Exchange API');
// make exchange module dynamic later
if (process.env.activeExchange == 'binance'){
logger.info('--- \tActive Exchange:' + process.env.activeExchange);
// activePairs = process.env.binancePairs;
const api = require('binance');
exchangeAPI = new api.BinanceRest({
key: process.env.binance_key,
secret: process.env.binance_secret,
timeout: parseInt(process.env.restTimeout), // Optional, defaults to 15000, is the request time out in milliseconds
recvWindow: parseInt(process.env.restRecvWindow), // Optional, defaults to 5000, increase if you're getting timestamp errors
disableBeautification: process.env.restBeautify != 'true'
});
exchangeAPI.WS = new api.BinanceWS();
}
var botOptions = {
UI: {
title: 'Top Potential Arbitrage Triplets, via: ' + process.env.binanceColumns
},
arbitrage: {
paths: process.env.binanceColumns.split(','),
start: process.env.binanceStartingPoint
},
storage: {
logHistory: false
},
trading: {
paperOnly: true,
// only candidates with over x% gain potential are queued for trading
minQueuePercentageThreshold: 3,
// how many times we need to see the same opportunity before deciding to act on it
minHitsThreshold: 5
}
},
ctrl = {
options: botOptions,
storage: {
trading: {
// queued triplets
queue: [],
// actively trading triplets
active: []
},
candidates: [],
streams: [],
pairRanks: []
},
logger: logger,
exchange: exchangeAPI
};
// load DBCore, then start streams once DB is up and connected
require('./lib/DBCore')(logger, (err, db)=>{
if (process.env.useMongo == 'true'){
ctrl.storage.db = db;
ctrl.options.storage.logHistory = true;
}
if (err){
ctrl.logger.error('MongoDB connection unavailable, history logging disabled: ' + err);
ctrl.options.storage.logHistory = false;
}
ctrl.UI = process.env.enableUI !== "false" ? require('./lib/UI')(ctrl.options) : null;
ctrl.events = require('./lib/EventsCore')(ctrl);
// We're ready to start. Load up the webhook streams and start making it rain.
require('./lib/BotCore')(ctrl);
ctrl.logger.info('----- Bot Startup Finished -----');
});