Skip to content

Commit

Permalink
make sure Gekko does not start advicing on historical data (in realti…
Browse files Browse the repository at this point in the history
…me mode)
  • Loading branch information
askmike committed Mar 8, 2017
1 parent 14372c1 commit 91df0cc
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 21 deletions.
24 changes: 12 additions & 12 deletions core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var fs = require('fs');
var semver = require('semver');
var program = require('commander');

var startTime = moment();

var _config = false;
var _package = false;
var _nodeVersion = false;
Expand All @@ -16,22 +18,17 @@ var _args = false;
// helper functions
var util = {
getConfig: function() {
// cache
if(_config)
return _config;

if(program.config) {
if(!program.config)
util.die('Please specify a config file.', true);

// we will use one single config file
if(!fs.existsSync(util.dirs().gekko + program.config))
util.die('Cannot find the specified config file.');
if(!fs.existsSync(util.dirs().gekko + program.config))
util.die('Cannot find the specified config file.', true);

_config = require(util.dirs().gekko + program.config);
return _config;
}

// build the config out of TOML files
var buildConfig = require(util.dirs().tools + 'configBuilder');
_config = buildConfig();
_config = require(util.dirs().gekko + program.config);
return _config;
},
// overwrite the whole config
Expand Down Expand Up @@ -88,7 +85,7 @@ var util = {

if(m) {
if(soft) {
log('\n ' + m + '\n\n');
log('\n ERROR: ' + m + '\n\n');
} else {
log('\n\nGekko encountered an error and can\'t continue');
log('\nError:\n');
Expand Down Expand Up @@ -160,6 +157,9 @@ var util = {
return true;
else
return false;
},
getStartTime: function() {
return startTime;
}
}

Expand Down
7 changes: 6 additions & 1 deletion plugins/sqlite/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ Reader.prototype.mostRecentWindow = function(from, to, next) {
ORDER BY start DESC
`, function(err, rows) {
if(err) {
log.error(err)

// bail out if the table does not exist
if(err.message.split(':')[1] === ' no such table')
return next(false);

log.error(err);
return util.die('DB error while reading mostRecentWindow');
}

Expand Down
18 changes: 16 additions & 2 deletions plugins/tradingAdvisor/baseTradingMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var dirs = util.dirs();
var log = require(dirs.core + 'log');

var ENV = util.gekkoEnv();
var mode = util.gekkoMode();
var startTime = util.getStartTime();

if(config.tradingAdvisor.talib.enabled) {
// verify talib is installed properly
Expand Down Expand Up @@ -208,13 +210,25 @@ if(ENV !== 'child-process') {

Base.prototype.propogateTick = function() {
this.update(this.candle);
if(this.requiredHistory <= this.age) {

var isAllowedToCheck = this.requiredHistory <= this.age;

// in live mode we might receive more candles
// than minimally needed. In that case check
// whether candle start time is > startTime
var isPremature;
if(mode === 'realtime')
isPremature = this.candle.start < startTime;
else
isPremature = false;

if(isAllowedToCheck && !isPremature) {
this.log();
this.check(this.candle);
}
this.processedTicks++;

// are we totally finished
// are we totally finished?
var done = this.age === this.processedTicks;
if(done && this.finishCb)
this.finishCb();
Expand Down
12 changes: 6 additions & 6 deletions sample-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ config.debug = true; // for additional logging / debugging
config.watch = {

// see https://github.com/askmike/gekko#supported-exchanges
exchange: 'Poloniex',
currency: 'USDT',
asset: 'BTC'
exchange: 'kraken',
currency: 'EUR',
asset: 'XBT'
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -29,8 +29,8 @@ config.watch = {
config.tradingAdvisor = {
enabled: true,
method: 'MACD',
candleSize: 60,
historySize: 25,
candleSize: 1,
historySize: 3,
adapter: 'sqlite',
talib: {
enabled: false,
Expand Down Expand Up @@ -284,6 +284,6 @@ config.importer = {
// understand this.
//
// Not sure? Read this first: https://github.com/askmike/gekko/issues/201
config['I understand that Gekko only automates MY OWN trading strategies'] = false;
config['I understand that Gekko only automates MY OWN trading strategies'] = true;

module.exports = config;

0 comments on commit 91df0cc

Please sign in to comment.