diff --git a/.gitignore b/.gitignore index 410e87b53..c8a2f2bde 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,4 @@ node_modules candles.csv cexio.db history +TMP_* \ No newline at end of file diff --git a/config.js b/config.js index b151975de..4fe789e3a 100644 --- a/config.js +++ b/config.js @@ -9,10 +9,18 @@ var config = {}; // Gekko stores historical history config.history = { - // in what directory should Gekko store + // what directory should Gekko store // and load historical data from? directory: './history/' } + +config.sqliteWriter = { + enabled: true, + storeCandles: true, + storeTrades: false, // NOT IMPLEMENTED + storeAdvice: false // NOT IMPLEMENTED +} + config.debug = true; // for additional logging / debugging // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/core/budfox/marketFetcher.js b/core/budfox/marketFetcher.js index 9d6d3dc88..6370cd15b 100644 --- a/core/budfox/marketFetcher.js +++ b/core/budfox/marketFetcher.js @@ -65,25 +65,21 @@ Fetcher.prototype._fetch = function(since) { Fetcher.prototype.fetch = function(since) { this.tries = 0; - log.debug('Requested', this.pair ,'trade data from', this.exchange.name, '...'); + log.debug('Requested', this.pair, 'trade data from', this.exchange.name, '...'); this._fetch(since); } Fetcher.prototype.processTrades = function(err, trades) { - if(err) { - log.warn(this.exhange.name, 'returned an error while fetching trades:', err); - log.debug('refetching...'); + if(err || _.isEmpty(trades)) { + if(err) { + log.warn(this.exhange.name, 'returned an error while fetching trades:', err); + log.debug('refetching...'); + } else + log.debug('Trade fetch came back empty, refetching...'); setTimeout(this._fetch, +moment.duration('s', 1)); return; } - // Make sure we have trades to check - if(_.isEmpty(trades)) { - log.debug('Trade fetch came back empty, refetching...'); - setTimeout(this.fetch, +moment.duration('s', 1)); - return; - } - this.batcher.write(trades); } diff --git a/core/pluginUtil.js b/core/pluginUtil.js index cbb5b8144..f42cdcecb 100644 --- a/core/pluginUtil.js +++ b/core/pluginUtil.js @@ -20,14 +20,16 @@ var pluginHelper = { cannotLoad: function(plugin) { // verify plugin dependencies are installed if(_.has(plugin, 'dependencies')) + var error = false; + _.each(plugin.dependencies, function(dep) { try { - require(dep.module); + var a = require(dep.module); } catch(e) { - return [ + error = [ 'The plugin', - module.slug, + plugin.slug, 'expects the module', dep.module, 'to be installed.', @@ -35,9 +37,11 @@ var pluginHelper = { 'it by running: \n\n', '\tnpm install', dep.module + '@' + dep.version - ]; + ].join(' '); } }); + + return error; }, // loads a plugin // @@ -72,10 +76,10 @@ var pluginHelper = { if(plugin.async) { var instance = new Constructor(util.defer(function(err) { next(err, instance); - })); + }), plugin); instance.meta = plugin; } else { - var instance = new Constructor; + var instance = new Constructor(plugin); instance.meta = plugin; _.defer(function() { next(null, instance); diff --git a/core/util.js b/core/util.js index 405c7c2dc..76cbd8681 100644 --- a/core/util.js +++ b/core/util.js @@ -99,15 +99,21 @@ var util = { console.log('Gekko version:', 'v' + util.getVersion()); console.log('Nodejs version:', process.version); }, - die: function(m) { + die: function(m, soft) { + console.log('death'); if(m) { - console.log('\n\nGekko encountered an error and can\'t continue'); - console.log('\nMeta debug info:\n'); - util.logVersion(); - console.log('\nError:\n'); - console.log(m, '\n\n'); + if(soft) { + console.log('\n', m, '\n\n'); + } else { + console.log('\n\nGekko encountered an error and can\'t continue'); + console.log('\nError:\n'); + console.log(m, '\n\n'); + console.log('\nMeta debug info:\n'); + util.logVersion(); + console.log(''); + } } - process.kill(); + process.exit(0); }, dirs: function() { var ROOT = __dirname + '/../'; diff --git a/gekko.js b/gekko.js index 9cfa6a41b..57d3f24de 100644 --- a/gekko.js +++ b/gekko.js @@ -116,8 +116,9 @@ var loadPlugins = function(next) { pluginParameters, pluginHelper.load, function(error, _plugins) { + if(error) - return util.die(error); + return util.die(error, true); plugins = _.compact(_plugins); next(); @@ -214,9 +215,9 @@ async.series( // everything is setup! - market = new Market(config.watch) + var market = new Market(config.watch) .start() - .pipe(new GekkoStream(candleConsumers)); + .pipe(new GekkoStream(candleConsumers)) // convert JS objects to JSON string // .pipe(new require('stringify-stream')()) diff --git a/plugins.js b/plugins.js index ea49ae343..6c7575eef 100644 --- a/plugins.js +++ b/plugins.js @@ -14,8 +14,20 @@ // backtest is during a backtest. // dependencies: a list of external npm modules this plugin requires to // be installed. -// emits: does this plugin emits events? +// emits: events emitted by this plugin that other plugins can subscribe to. var plugins = [ + { + name: 'SQLite Datastore', + description: 'Store candles, trades and advices in a SQLite database', + slug: 'sqliteWriter', + version: 0.1, + async: true, + modes: ['realtime'], + dependencies: [{ + module: 'sqlite3', + version: '3.1.3' + }] + }, { name: 'Trading Advisor', description: 'Calculate trading advice', @@ -48,7 +60,7 @@ var plugins = [ }, { name: 'Mailer', - description: 'Sends you email yourself everytime Gekko has new advice.', + description: 'Sends you an email everytime Gekko has new advice.', slug: 'mailer', async: true, modes: ['realtime'], diff --git a/plugins/adviceLogger.js b/plugins/adviceLogger.js index 29bb2f9f4..19d6e001d 100644 --- a/plugins/adviceLogger.js +++ b/plugins/adviceLogger.js @@ -16,7 +16,7 @@ Actor.prototype.processTrade = function(trade) { Actor.prototype.processAdvice = function(advice) { console.log() log.info('We have new trading advice!'); - log.info('\t Position to take:', advice.recommandation); + log.info('\t Position:', advice.recommandation); log.info('\t Market price:', this.price); log.info('\t Based on market time:', this.marketTime.format('YYYY-MM-DD HH:mm:ss')); console.log()