first commit

This commit is contained in:
Francois Klieber committed 2021-06-06 20:25:14 +02:00
commit aa7869eb33
386 files changed
+69375

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
/*
Gekko is a Bitcoin trading bot for popular Bitcoin exchanges written
in node, it features multiple trading methods using technical analysis.
If you are interested in how Gekko works, read more about Gekko's
architecture here:
https://github.com/askmike/gekko/blob/stable/docs/internals/architecture.md
Disclaimer:
USE AT YOUR OWN RISK!
The author of this project is NOT responsible for any damage or loss caused
by this software. There can be bugs and the bot may not perform as expected
or specified. Please consider testing it first with paper trading and/or
backtesting on historical data. Also look at the code to see what how
it is working.
*/
var start = (mode, config) => {
var util = require(__dirname + '/../../util');
// force correct gekko env
util.setGekkoEnv('child-process');
var dirs = util.dirs();
// force correct gekko mode & config
util.setGekkoMode(mode);
util.setConfig(config);
var pipeline = require(dirs.core + 'pipeline');
pipeline({
config: config,
mode: mode
});
}
process.send('ready');
process.on('message', function(m) {
if(m.what === 'start')
start(m.mode, m.config);
if(m.what === 'exit')
process.exit(0);
});
process.on('disconnect', function() {
console.log('disconnect');
process.exit(-1);
})
process
.on('unhandledRejection', (message, p) => {
console.error('unhandledRejection', message);
process.send({type: 'error', message: message});
})
.on('uncaughtException', err => {
console.error('uncaughtException', err);
process.send({type: 'error', error: err});
process.exit(1);
});
@@ -0,0 +1,25 @@
// Relay the backtest message it when it comes in.
module.exports = done => {
let backtest;
return {
message: message => {
if(message.type === 'error') {
done(message.error);
}
if(message.backtest) {
done(null, message.backtest);
}
},
exit: status => {
if(status !== 0) {
if(backtest)
console.error('Child process died after finishing backtest');
else
done('Child process has died.');
}
}
}
}
@@ -0,0 +1,26 @@
module.exports = cb => {
return {
message: message => {
if(message.event === 'marketUpdate')
cb(null, {
done: false,
latest: message.payload
})
else if(message.type === 'error') {
cb(message.error);
}
else if(message.type === 'log')
console.log(message.log);
},
exit: status => {
if(status !== 0)
return cb('Child process has died.');
else
cb(null, { done: true });
}
}
}
@@ -0,0 +1,24 @@
// pass back all messages as is
// (except for errors and logs)
module.exports = cb => {
return {
message: message => {
if(message.type === 'error') {
cb(message.error);
}
else
cb(null, message);
},
exit: status => {
if(status !== 0)
cb('Child process has died.');
else
cb(null, { done: true });
}
}
}
+34
View File
@@ -0,0 +1,34 @@
var fork = require('child_process').fork;
module.exports = (mode, config, callback) => {
var debug = typeof v8debug === 'object';
if (debug) {
process.execArgv = [];
}
var child = fork(__dirname + '/child');
// How we should handle client messages depends
// on the mode of the Pipeline that is being ran.
var handle = require('./messageHandlers/' + mode + 'Handler')(callback);
var message = {
what: 'start',
mode: mode,
config: config
};
child.on('message', function(m) {
if(m === 'ready')
return child.send(message);
if(m === 'done')
return child.send({what: 'exit'});
handle.message(m);
});
child.on('exit', handle.exit);
return child;
}