This repository has been archived on 2025-10-29. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2021-06-06 20:25:14 +02:00

69 lines
1.3 KiB
JavaScript

// example usage:
// let config = {
// watch: {
// exchange: 'poloniex',
// currency: 'USDT',
// asset: 'BTC'
// },
// daterange: {
// from: '2016-05-22 11:22',
// to: '2016-06-03 19:56'
// },
// adapter: 'sqlite',
// sqlite: {
// path: 'plugins/sqlite',
// dataDirectory: 'history',
// version: 0.1,
// dependencies: [{
// module: 'sqlite3',
// version: '3.1.4'
// }]
// },
// candleSize: 100
// }
// module.exports(config, function(err, data) {
// console.log('FINAL CALLBACK');
// console.log('err', err);
// console.log('data', data.length);
// })
const fork = require('child_process').fork;
const _ = require('lodash');
module.exports = (config, callback) => {
var debug = typeof v8debug === 'object';
if (debug) {
process.execArgv = [];
}
const child = fork(__dirname + '/child');
const message = {
what: 'start',
config
}
const done = _.once(callback);
child.on('message', function(m) {
if(m === 'ready')
return child.send(message);
// else we are done and have candles!
done(null, m);
if (this.connected) {
this.disconnect();
}
});
child.on('exit', code => {
if(code !== 0)
done('ERROR, unable to load candles, please check the console.');
});
}