forked from drbeep/BitBot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
126 lines (94 loc) · 3.34 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var _ = require('underscore');
var cluster = require('cluster');
var loggingservice = require('./services/loggingservice.js');
//------------------------------Config
var config = require('./config.js');
//------------------------------Config
var app = function() {
_.bindAll(this, 'appListener', 'launchTrader', 'launchBacktester', 'launchGa', 'initializeModules', 'start');
};
app.prototype.appListener = function() {
this.app.on('done', function() {
this.logger.log('App closed.');
}.bind(this));
};
app.prototype.launchTrader = function() {
this.logger.log('----------------------------------------------------');
this.logger.log('Launching trader module.');
this.logger.log('----------------------------------------------------');
this.app = require('./apps/trader.js');
this.appListener();
this.app.start();
};
app.prototype.launchBacktester = function() {
this.logger.log('----------------------------------------------------');
this.logger.log('Launching backtester module.');
this.logger.log('----------------------------------------------------');
this.app = require('./apps/backtester.js');
this.appListener();
this.app.start();
};
app.prototype.launchGa = function() {
this.logger.log('----------------------------------------------------');
this.logger.log('Launching ga module.');
this.logger.log('----------------------------------------------------');
this.app = require('./apps/ga.js');
this.appListener();
this.app.start();
};
app.prototype.launchReset = function(collection) {
this.logger.log('----------------------------------------------------');
this.logger.log('Launching ga module.');
this.logger.log('----------------------------------------------------');
this.app = require('./apps/reset.js');
this.appListener();
this.app.start(collection);
};
app.prototype.initializeModules = function(appName) {
this.logger = new loggingservice(appName, config.debug);
};
app.prototype.start = function() {
var argument = process.argv[2];
if(!argument) {
this.appName = 'trader';
this.run = this.launchTrader;
} else {
if(argument === '-b') {
this.appName = 'backtester';
this.run = this.launchBacktester;
} else if(argument === '-g') {
this.appName = 'ga';
this.run = this.launchGa;
} else if(argument === '-rb') {
this.appName = 'reset';
this.run = function() {
this.launchReset('balance');
}.bind(this);
} else if(argument === '-ro') {
this.appName = 'reset';
this.run = function() {
this.launchReset('bestOrganism');
}.bind(this);
} else {
this.appName = 'app';
run = null;
}
}
this.initializeModules(this.appName);
//------------------------------AnnounceStart
this.logger.log('----------------------------------------------------');
this.logger.log('Starting BitBot v0.9.7');
this.logger.log('Real Trading Enabled = ' + config.tradingEnabled);
this.logger.log('Working Dir = ' + process.cwd());
this.logger.log('----------------------------------------------------');
//------------------------------AnnounceStart
if(this.run) {
this.run();
} else {
this.logger.log('Invalid argument, supported options:');
this.logger.log('-b: Launch Backtester');
this.logger.log('-rb: Reset balance');
}
};
var application = new app();
application.start();