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

Support external config files #2163

@bettimms

Description

@bettimms

I was playing with a project to generate multiple config files based on currency and strategy and I didn't want to "pollute" gekko project with custom files. What I was trying to do is feed gekko with config file and start it from a different project(location) and seems it's not supported because of this part of the code in core/util.js:

// helper functions
var util = {
  getConfig: function() {
    // cache
    if(_config)
      return _config;

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

    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;
  },
...

Current code supports only config files located within gekko folder!

I'd propose to support both cases so config file can be provided from within gekko project or external path. Making this small change could make it more flexible and support cases like mine where you don't want to make changes directly in gekko project but adding features from external projects:

// helper functions
var util = {
  getConfig: function() {
    // cache
    if (_config)
      return _config;

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

    try {
      _config = require(program.config);
      return _config;
    }
    catch (e) {
      if (e instanceof Error && e.code === 'MODULE_NOT_FOUND') {
        _config = require(util.dirs().gekko + program.config);
        return _config;
      }
      else
        util.die('Cannot find the specified config file.', true);
    }
  },

So we could start gekko also like so:

node /path/to/gekko/gekko --config /path/to/config.js

I could make a PR if needed!

UPDATE: This method supports current cli method and the method I suggested. It’ll not remove current option!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions