Skip to main content

Access Gunbot's main config in custom AutoConfig filters via this.config

· 4 min read

Custom AutoConfig filters can read settings from your main config.js through the read-only context variable this.config. This lets filters use global, exchange, strategy, and pair settings alongside market data.

Use the AutoConfig wizard

Nearly every option that follows can be set without editing files by hand.
Click the (three-dots) menu ➜ AutoConfig, step through the wizard, and press Save; it will write a correct autoconfig.json for you.

Understanding this.config

In a custom filter, this.config is a snapshot of your full config.js at the time the filter runs.

You can read:

  • Global bot settings (e.g., this.config.bot.WATCH_MODE, this.config.bot.VERBOSE).
  • Exchange settings (e.g., this.config.exchanges[this.exchangeName].delay).
  • Strategy definitions (e.g., this.config.strategies.stepgrid.GAIN).
  • Specific pair overrides (e.g., this.config.pairs[this.exchangeName][this.pairName].override.GAIN).
  • GUI settings and more.

How to Use this.config in a Script

Use normal JavaScript property access (dot or bracket notation). The path matches your config.js structure.

Consider this AutoConfig job with a custom filter:

{
"adaptivePairManager": {
"enabled": true,
"type": "manageOverrides", // Job to change overrides
"schedule": "*/5 * * * *",
"pairs": {
"exchange": "binance",
"include": "USDT-"
},
"filters": {
"checkGlobalSettingAndPairOverride": {
"filterType": "custom",
"script": "/* Accessing this.config */ \n const jobName = 'adaptivePairManager'; /* Or get dynamically */ \n const currentExchange = this.exchangeName; \n const currentPair = this.pairName; \n \n // Check a global bot setting \n if (this.config.bot.WATCH_MODE === true) { \n console.log('Bot is in WATCH_MODE, filter fails for ' + currentPair); \n return false; // Don't apply overrides if bot is in watch mode \n } \n \n // Check if the pair itself has a specific override \n let currentPairGainOverride = this.config.pairs[currentExchange]?.[currentPair]?.override?.GAIN; \n \n if (typeof currentPairGainOverride === 'number' && currentPairGainOverride < 0.5) { \n console.log('GAIN for ' + currentPair + ' is already very low (' + currentPairGainOverride + '), filter passes to adjust it.'); \n return true; // Pass if GAIN is already set and very low \n } \n \n // Accessing a strategy parameter (assuming pair has a strategy assigned) \n const pairStrategyName = this.config.pairs[currentExchange]?.[currentPair]?.strategy; \n if (pairStrategyName) { \n const strategyStopLimit = this.config.strategies[pairStrategyName]?.STOP_LIMIT; \n if (typeof strategyStopLimit === 'number' && strategyStopLimit < 100) { \n console.log('Strategy ' + pairStrategyName + ' STOP_LIMIT is low for ' + currentPair + ', filter passes.'); \n return true; \n } \n } \n \n return false;"
}
},
"overrides": { // Overrides to apply if the custom filter passes
"GAIN": 1,
"STOP_LIMIT": 200
}
}
}

In the script for checkGlobalSettingAndPairOverride:

  1. this.config.bot.WATCH_MODE === true: Checks the global WATCH_MODE. If enabled, the filter fails.
  2. this.config.pairs[currentExchange]?.[currentPair]?.override?.GAIN: Reads the pair’s override using optional chaining.
  3. this.config.strategies[pairStrategyName]?.TRADING_LIMIT: Reads the assigned strategy’s TRADING_LIMIT.

Practical Examples and Use Cases

  1. Global settings:

    • Only add new pairs if WATCH_MODE is false.
    • Adjust logic based on a custom global value like this.config.bot.riskLevel.
  2. Pair overrides:

    • Check a pair’s STOP_LIMIT before tightening it further.
    • Filter for pairs with overrides below a threshold.
  3. Default strategy parameters:

    • Read defaults when a pair has no override, e.g. this.config.strategies[strategyName].GAIN.
  4. Exchange settings:

    • Read exchange delay: const_delay = this.config.exchanges[this.exchangeName].delay;

Important Considerations

  • Read-only: Changes to this.config do not persist. To write changes, the job itself must run (for example, addPairs or manageOverrides).
  • Correct paths: Invalid paths return undefined, so confirm your config.js structure.