Skip to content

Commit

Permalink
glue everything together
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed May 13, 2016
1 parent 463c203 commit a8395b1
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 31 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ node_modules
candles.csv
cexio.db
history
TMP_*
10 changes: 9 additions & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
18 changes: 7 additions & 11 deletions core/budfox/marketFetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 10 additions & 6 deletions core/pluginUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,28 @@ 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.',
'However it is not, install',
'it by running: \n\n',
'\tnpm install',
dep.module + '@' + dep.version
];
].join(' ');
}
});

return error;
},
// loads a plugin
//
Expand Down Expand Up @@ -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);
Expand Down
20 changes: 13 additions & 7 deletions core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '/../';
Expand Down
7 changes: 4 additions & 3 deletions gekko.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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')())
Expand Down
16 changes: 14 additions & 2 deletions plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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'],
Expand Down
2 changes: 1 addition & 1 deletion plugins/adviceLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a8395b1

Please sign in to comment.