Skip to content

Commit

Permalink
use toml strat config for commandline gekko
Browse files Browse the repository at this point in the history
  • Loading branch information
askmike committed Nov 1, 2016
1 parent ce4ff40 commit a333852
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 163 deletions.
1 change: 1 addition & 0 deletions config/strategies/custom.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
my_custom_setting = 10
3 changes: 2 additions & 1 deletion core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ var util = {
importers: ROOT + 'importers/exchanges/',
tools: ROOT + 'core/tools/',
workers: ROOT + 'core/workers/',
web: ROOT + 'web/'
web: ROOT + 'web/',
config: ROOT + 'config/'
}
},
inherit: function(dest, source) {
Expand Down
10 changes: 7 additions & 3 deletions methods/debug-advice.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
var _ = require('lodash');
var settings = {
wait: 1,
advice: 'long'
};

var config = require('../core/util.js').getConfig();
var settings = config['debug-advice'];
// -------

var _ = require('lodash');

var method = {
init: _.noop,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gekko",
"version": "0.4.0",
"version": "0.4.1",
"description": "A bitcoin trading bot for auto trading at various exchanges",
"keywords": [
"trading",
Expand Down Expand Up @@ -45,6 +45,7 @@
"semver": "2.2.1",
"sqlite3": "3.1.4",
"tiny-promisify": "^0.1.1",
"toml": "^2.3.0",
"zaif.jp": "^0.1.4"
},
"devDependencies": {
Expand Down
3 changes: 2 additions & 1 deletion plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ var plugins = [
slug: 'tradingAdvisor',
async: true,
modes: ['realtime', 'backtest'],
emits: ['advice']
emits: ['advice'],
path: config => 'tradingAdvisor/tradingAdvisor.js',
},
{
name: 'IRC bot',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var _ = require('lodash');
var util = require('../core/util.js');
var util = require('../../core/util');
var config = util.getConfig();
var dirs = util.dirs();
var log = require('../core/log.js');
var log = require(dirs.core + 'log');

var ENV = util.gekkoEnv();

Expand All @@ -24,7 +24,7 @@ if(config.tradingAdvisor.talib.enabled) {
var talib = require(dirs.core + 'talib');
}

var indicatorsPath = '../methods/indicators/';
var indicatorsPath = dirs.methods + 'indicators/';

var Indicators = {
MACD: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var util = require('../core/util');
var util = require('../../core/util');
var _ = require('lodash');
var fs = require('fs');
var toml = require('toml');

var config = util.getConfig();
var dirs = util.dirs();
Expand All @@ -16,6 +17,10 @@ var Actor = function(done) {

this.batcher = new CandleBatcher(config.tradingAdvisor.candleSize);

this.methodName = config.tradingAdvisor.method;

this.generalizeMethodSettings();

this.setupTradingMethod();

var mode = util.gekkoMode();
Expand All @@ -30,19 +35,42 @@ var Actor = function(done) {

util.makeEventEmitter(Actor);

Actor.prototype.generalizeMethodSettings = function() {
// method settings can be either part of the main config OR a seperate
// toml configuration file. In case of the toml config file we need to
// parse and attach to main config object

// config already part of
if(config[this.methodName]) {
log.warn('\t', 'Config already has', this.methodName, 'parameters. Ignoring toml file');
return;
}

var tomlFile = dirs.config + 'strategies/' + this.methodName + '.toml';

if(!fs.existsSync(tomlFile)) {
log.warn('\t', 'toml configuration file not found.');
return;
}

var rawSettings = fs.readFileSync(tomlFile);
config[this.methodName] = toml.parse(rawSettings);

util.setConfig(config);
}

Actor.prototype.setupTradingMethod = function() {
var methodName = config.tradingAdvisor.method;

if(!fs.existsSync(dirs.methods + methodName + '.js'))
util.die('Gekko doesn\'t know the method ' + methodName);
if(!fs.existsSync(dirs.methods + this.methodName + '.js'))
util.die('Gekko doesn\'t know the method ' + this.methodName);

log.info('\t', 'Using the trading method: ' + methodName);
log.info('\t', 'Using the trading method: ' + this.methodName);

var method = require(dirs.methods + methodName);
var method = require(dirs.methods + this.methodName);

// bind all trading method specific functions
// to the Consultant.
var Consultant = require(dirs.core + 'baseTradingMethod');
var Consultant = require('./baseTradingMethod');

_.each(method, function(fn, name) {
Consultant.prototype[name] = fn;
Expand Down
147 changes: 0 additions & 147 deletions sample-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,153 +38,6 @@ config.tradingAdvisor = {
}
}

// Exponential Moving Averages settings:
config.DEMA = {
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
short: 10,
long: 21,
// amount of candles to remember and base initial EMAs on
// the difference between the EMAs (to act as triggers)
thresholds: {
down: -0.025,
up: 0.025
}
};

// MACD settings:
config.MACD = {
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
short: 10,
long: 21,
signal: 9,
// the difference between the EMAs (to act as triggers)
thresholds: {
down: -0.025,
up: 0.025,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
}
};

// PPO settings:
config.PPO = {
// EMA weight (α)
// the higher the weight, the more smooth (and delayed) the line
short: 12,
long: 26,
signal: 9,
// the difference between the EMAs (to act as triggers)
thresholds: {
down: -0.025,
up: 0.025,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 2
}
};

// Uses one of the momentum indicators but adjusts the thresholds when PPO is bullish or bearish
// Uses settings from the ppo and momentum indicator config block
config.varPPO = {
momentum: 'TSI', // RSI, TSI or UO
thresholds: {
// new threshold is default threshold + PPOhist * PPOweight
weightLow: 120,
weightHigh: -120,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 0
}
};

// RSI settings:
config.RSI = {
interval: 14,
thresholds: {
low: 30,
high: 70,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
}
};

// TSI settings:
config.TSI = {
short: 13,
long: 25,
thresholds: {
low: -25,
high: 25,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
}
};

// Ultimate Oscillator Settings
config.UO = {
first: {weight: 4, period: 7},
second: {weight: 2, period: 14},
third: {weight: 1, period: 28},
thresholds: {
low: 30,
high: 70,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 1
}
};

// CCI Settings
config.CCI = {
constant: 0.015, // constant multiplier. 0.015 gets to around 70% fit
history: 90, // history size, make same or smaller than history
thresholds: {
up: 100, // fixed values for overbuy upward trajectory
down: -100, // fixed value for downward trajectory
persistence: 0 // filter spikes by adding extra filters candles
}
};

// StochRSI settings
config.StochRSI = {
interval: 3,
thresholds: {
low: 20,
high: 80,
// How many candle intervals should a trend persist
// before we consider it real?
persistence: 3
}
};


// custom settings:
config.custom = {
my_custom_setting: 10,
}

config['talib-macd'] = {
parameters: {
optInFastPeriod: 10,
optInSlowPeriod: 21,
optInSignalPeriod: 9
},
thresholds: {
down: -0.025,
up: 0.025,
}
}

config['debug-advice'] = {
wait: 1,
advice: 'long'
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// CONFIGURING PLUGINS
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit a333852

Please sign in to comment.