Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
gekkoStream wrapper for plugins; hooked up to budfox
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed Feb 14, 2015
1 parent e6d438f commit ff6cd29
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 185 deletions.
2 changes: 1 addition & 1 deletion core/baseTradingMethod.js
Expand Up @@ -35,7 +35,7 @@ var Base = function() {

// defaults
this.requiredHistory = 0;
this.priceValue = 'c';
this.priceValue = 'close';
this.indicators = {};

// make sure we have all methods
Expand Down
2 changes: 1 addition & 1 deletion core/budfox/budfox.js
Expand Up @@ -15,7 +15,7 @@ var Readable = require('stream').Readable;
var BudFox = function(config) {
_.bindAll(this);

Readable.call(this, { objectMode: true });
Readable.call(this, {objectMode: true});

// BudFox internal modules:

Expand Down
24 changes: 24 additions & 0 deletions core/gekkoStream.js
@@ -0,0 +1,24 @@
// Small writable stream wrapper that
// passes data to all `candleProcessors`.

var Writable = require('stream').Writable;
var _ = require('lodash');

var Gekko = function(candleProcessors) {
this.candleProcessors = candleProcessors;
Writable.call(this, {objectMode: true});
}

Gekko.prototype = Object.create(Writable.prototype, {
constructor: { value: Gekko }
});

Gekko.prototype._write = function(chunk, encoding, callback) {
_.each(this.candleProcessors, function(p) {
p.processCandle(chunk);
});

callback();
}

module.exports = Gekko;
3 changes: 0 additions & 3 deletions core/log.js
Expand Up @@ -35,9 +35,6 @@ Log.prototype = {
},
info: function() {
this._write('info', arguments);
},
empty: function() {
this.output.info('');
}
}

Expand Down
95 changes: 0 additions & 95 deletions core/moduleHelper.js

This file was deleted.

90 changes: 90 additions & 0 deletions core/pluginUtil.js
@@ -0,0 +1,90 @@
var _ = require('lodash');
var async = require('async');

var util = require(__dirname + '/util');

var log = require(util.dirs().core + 'log');

var config = util.getConfig();
var pluginDir = util.dirs().plugins;
var gekkoMode = util.gekkoMode();

var pluginHelper = {
// Checks whether we can load a module

// @param Object plugin
// plugin config object
// @return String
// error message if we can't
// use the module.
cannotLoad: function(plugin) {
// verify plugin dependencies are installed
if(_.has(plugin, 'dependencies'))
_.each(plugin.dependencies, function(dep) {
try {
require(dep.module);
}
catch(e) {
return [
'The plugin',
module.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
];
}
});
},
// loads a plugin
//
// @param Object plugin
// plugin config object
// @param Function next
// callback
load: function(plugin, next) {

plugin.config = config[plugin.slug];

if(!plugin.config)
log.warn(
'unable to find',
plugin.slug,
'in the config. Is your config up to date?'
);

if(!plugin.config || !plugin.config.enabled)
return next();

log.info('Setting up:');
log.info('\t', plugin.name);
log.info('\t', plugin.description);

var cannotLoad = pluginHelper.cannotLoad(plugin);
if(cannotLoad)
return next(cannotLoad);

var Constructor = require(pluginDir + plugin.slug);

if(plugin.async) {
var instance = new Constructor(util.defer(function(err) {
next(err, instance);
}));
instance.meta = plugin;
} else {
var instance = new Constructor;
instance.meta = plugin;
_.defer(function() {
next(null, instance);
});
}

if(!plugin.silent)
log.info('\n');
}
}

module.exports = pluginHelper;

0 comments on commit ff6cd29

Please sign in to comment.