-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
bin.js
205 lines (157 loc) · 6.08 KB
/
bin.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/env node
// Initialization the PacMan and key store.
const PacMan = require ('./PacMan');
const keystore = PacMan.yaml.read(PacMan.path.root('keystore.yaml')) || {};
const exchange = PacMan.yaml.read(PacMan.path.root('exchange.yaml')) || {};
// Obtaining instances of the essence of architecture
const instances = {
getaway: {
rest: require(PacMan.path.root('/getaway/rest')),
app: require(PacMan.path.root('/getaway/app'))
},
preprocessor: {
ccxt: require(PacMan.path.root('/preprocessor/ccxt'))
},
processor: {
indicators: require(PacMan.path.root('/processor/indicators'))
},
driver: {
bybit: require(PacMan.path.root('/drivers/bybit')),
deribit: require(PacMan.path.root('/drivers/deribit')),
bitmex: require(PacMan.path.root('/drivers/bitmex'))
},
transport: {
indicators: require(PacMan.path.root('/transport/indicators'))
},
crossover: {
bigData: require(PacMan.path.root('/crossover/bigData'))
},
bridge: {
vm: require(PacMan.path.root('/bridge/vm'))
}
}
// Map
var map = {
driver: {},
getaway: {},
transport: {},
processor: {}
};
// Single code
const pccxt = new instances.preprocessor.ccxt ();
const bd = new instances.crossover.bigData ();
const vm = new instances.bridge.vm ();
const tinds = new instances.transport.indicators ();
const pinds = new instances.processor.indicators (exchange);
// Configure the CCXT preprocessor
pccxt.use ('driver', 'ccxt', PacMan.ccxt);
pccxt.use ('store', 'keystore', keystore);
pccxt.on ('initExchange', function (event={}) {
if (event.exchange in map.driver) {
if (map.driver[event.exchange].meta.type == 'exchange' && map.driver[event.exchange].meta.exchange == event.exchange) {
const driver = map.driver[event.exchange];
if ('use' in driver) {
vm.use ('public', `$${driver.meta.exchange}`, event.object);
driver.use ('commutator', 'ccxt', event.object);
driver.init ();
}
}
}
});
// Configure the BigData crossover
bd.use ('transport', 'indicators', tinds);
bd.use ('transfer', 'io', PacMan.io);
bd.use ('bridge', 'vm', vm);
bd.use ('store', 'cache', PacMan.cache);
// Configure indicator transport
tinds.use('logger', 'logger', PacMan.winston)
tinds.use('processor', 'indicators', pinds);
// Configure VM bridge
vm.use ('private', 'keystore', keystore);
vm.use ('private', 'environment', PacMan.vm);
vm.use ('private', 'fs', PacMan.fs);
vm.use ('private', 'alias', PacMan.VMAlais);
vm.use ('public', 'driver', map.driver);
vm.use ('public', 'console', console);
vm.use ('public', 'read', (file, callback) => {
return PacMan.fs.readFile(PacMan.path.root(`/virtual/libs/${file}`), 'utf8', function (err, data) {
callback(data);
})
});
// Check if debuggers are enabled
if (PacMan.yargs.visualization) {
// Debbug message
PacMan.print([
`Welcome to Event+ VM Visualization`,
`---------------------------`,
'Now the full virtual machine state dump will be sent to the console',
PacMan.yargs.file ? 'WARNING: A file with the virtual machine data dump can reach 1TB in 10 minutes. Be careful' : ''
]);
// Specific var?
if (PacMan.yargs.watch) {
vm.on ('context', Event => {
// Write to file?
if (PacMan.yargs.file) {
PacMan.fs.appendFile(PacMan.yargs.file, "\n\n" + JSON.stringify(Event[PacMan.yargs.watch], null, 2), function () {});
} else {
console.log('');
console.log(`Virtual Machine DUMP on ${Date.now()}`);
console.log(Event[PacMan.yargs.watch]);
}
})
// Dump all data
} else {
vm.on ('context', Event => {
// Write to file?
if (PacMan.yargs.file) {
PacMan.fs.appendFile(PacMan.yargs.file, "\n\n" + JSON.stringify(Event, null, 2), function () {});
} else {
console.log('');
console.log(`Virtual Machine DUMP on ${Date.now()}`);
console.log(Event);
}
})
}
}
// Go through the map of instances
for (const [name, instance] of Object.entries(instances)) {
switch (name) {
// Install and configure the driver environment
case 'driver':
for (const [name, driver] of Object.entries(instance)) {
map.driver[name] = new driver();
map.driver[name].use('store', 'keystore', keystore[name] || {});
map.driver[name].use('store', 'exchange', exchange || {});
map.driver[name].use('store', 'cache', PacMan.cache || false);
map.driver[name].use('commutator', 'request', PacMan.request || false);
map.driver[name].use('commutator', 'wss', PacMan.websocket.w3cwebsocket || false);
bd.use ('driver', name, map.driver[name]);
tinds.use ('driver', name, map.driver[name]);
// Driver initialization comes later.
}
break;
// Install and configure the getaway environment
case 'getaway':
for (const [name, getaway] of Object.entries(instance)) {
map.getaway[name] = new getaway();
map.getaway[name].use('commutator', 'mysql', PacMan.mysql || {});
map.getaway[name].use('router', 'express', PacMan.appExpress || {});
map.getaway[name].use('router', 'passport', PacMan.passport || {});
map.getaway[name].use('router', 'authenticationMiddleware', PacMan.passport.authenticationMiddleware || {});
bd.use ('getaway', name, map.getaway[name]);
map.getaway[name].init();
}
break;
}
}
// Execute boot code
for (const init of [pccxt, vm, bd, tinds]) {
init.init();
}
// Welcome message
PacMan.print([
`Welcome to Event+`,
`---------------------------`,
`HTTP URL: http://${PacMan.httpURL.join(':')}`,
`HTTPS URL: https://${PacMan.httpsURL.join(':')}`
]);