When writing custom JavaScript filters for Gunbot's AutoConfig, you often need to make decisions based not just on market data, but also on settings from your main Gunbot configuration (config.js
). AutoConfig provides a powerful context variable, this.config
, which gives your custom scripts read-only access to the entire config.js
object structure.
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
โ
Inside the JavaScript environment of an AutoConfig custom
filter, the this
keyword refers to a special context object. One of its most useful properties is config
. This this.config
object is essentially a live (at the time of filter execution) JavaScript representation of your entire config.js
file.
This means your custom filter can inspect:
- 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.
This allows for highly adaptive filter logic that can respond to the overall configuration of your Gunbot instance.
How to Use this.config
in a Scriptโ
You access values from this.config
using standard JavaScript object property access (dot notation or bracket notation). The path to the desired setting mirrors its location in 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
:
this.config.bot.WATCH_MODE === true
: It checks if the globalWATCH_MODE
is enabled. If so, the filter fails, preventing overrides from being applied.this.config.pairs[currentExchange]?.[currentPair]?.override?.GAIN
: It safely accesses theGAIN
override specific to the current pair being evaluated. The?.
(optional chaining) prevents errors if parts of the path don't exist.this.config.strategies[pairStrategyName]?.TRADING_LIMIT
: It retrieves theTRADING_LIMIT
from the definition of the strategy currently assigned to the pair.
Practical Examples and Use Casesโ
Conditional Logic Based on Global Settings:
- Only add new pairs if
WATCH_MODE
isfalse
. - Adjust filter sensitivity based on a custom global setting in
config.js
likethis.config.bot.riskLevel = "high"
.
- Only add new pairs if
Interacting with Pair-Specific Overrides:
- A
manageOverrides
job could check if a pair'sSTOP_LIMIT
is already very tight before attempting to tighten it further. - Filter for pairs whose
STOP_LIMIT
override (used as an example for a numeric parameter) is below a certain threshold.
- A
Reading Default Strategy Parameters:
- If a pair has no
override
forGAIN
, your filter could read the defaultGAIN
from its assigned strategy definition:this.config.strategies[strategyName].GAIN
.
- If a pair has no
Checking Exchange-Level Settings:
- Verify if the target exchange is marked as
enabled
inconfig.js
(though AutoConfig itself usually handles this at a higher level). const_delay = this.config.exchanges[this.exchangeName].delay;
- Verify if the target exchange is marked as
Important Considerationsโ
- Read-Only Access:
this.config
provides a snapshot for reading. Any modifications your script makes tothis.config
(e.g.,this.config.bot.WATCH_MODE = false;
) will not persist to your actualconfig.js
file and will only affect thethis.config
object within the current script's execution scope. To changeconfig.js
, an AutoConfig job must successfully complete its intended action (e.g., anaddPairs
ormanageOverrides
job type writing to the config). - Configuration Structure Awareness: You need to know the structure of your
config.js
to correctly path to the settings you need. An incorrect path will result inundefined
.
Using this.config
in your custom AutoConfig filters dramatically expands their capabilities, allowing for intelligent, context-aware automation that can adapt to your overall Gunbot setup and strategy configurations. It enables a deeper integration between AutoConfig's decision-making and your established Gunbot settings.