Control Strategy Parameters from the GUI
Gunbot provides the option to control specific parameters of a custom strategy for a particular trading pair using "pair overrides." This powerful feature allows you to define variables within your strategy script that can then be adjusted directly from the Gunbot browser interface, offering flexibility without needing to modify the strategy code itself.
Pair overrides allow you to customize strategy settings for individual trading pairs. For custom strategies, this means you can expose your own defined parameters to the GUI.
To utilize pair overrides for your custom strategy parameters, follow this process:
Define Overrides in
config.js
or via GUI: You can set up your custom overrides directly in theconfig.js
file under thepairs
section for a specific pair, or more commonly, you can add these overrides through the Gunbot GUI. When you edit a pair's strategy settings and select your custom strategy, you can add new key-value pairs in the "Overrides" section. These will then be saved to yourconfig.js
.Example
config.js
structure for overrides:// Example snippet from config.js
"pairs": {
"binance": {
"USDT-BTC": {
"strategy": "custom", // Your custom strategy filename (e.g., myAwesomeStrategy.js)
"enabled": true,
"override": {
"MY_CUSTOM_THRESHOLD": 0.5,
"TRAILING_PERCENTAGE": "1.2", // Note: GUI might save numbers as strings
"ENABLE_SPECIAL_FEATURE": true
}
}
}
}In the GUI, these would appear as editable fields for the USDT-BTC pair when your custom strategy is selected.
Access Overrides in Your Strategy Code: Within your custom strategy JavaScript file, you can access these override values through the
gb.data.pairLedger.whatstrat
object. This object is a merged collection of all Gunbot strategy parameters and any pair-specific overrides you've defined. Pair overrides take precedence over default strategy values if there are naming conflicts (though for custom parameters, this is less of a concern).Example strategy code to access the overrides:
// Accessing the custom overrides defined for the pair
const customThreshold = parseFloat(gb.data.pairLedger.whatstrat.MY_CUSTOM_THRESHOLD);
const trailingPercentage = parseFloat(gb.data.pairLedger.whatstrat.TRAILING_PERCENTAGE);
const isSpecialFeatureEnabled = gb.data.pairLedger.whatstrat.ENABLE_SPECIAL_FEATURE;
// Always validate and parse inputs, especially if they can be strings from the GUI
if (isNaN(customThreshold)) {
// Handle error or use a default value
console.log('MY_CUSTOM_THRESHOLD is not a valid number.');
}
if (isSpecialFeatureEnabled === true) {
// Implement special feature logic
}
Important Considerations:
- Data Types: Values entered through the GUI override section are often saved as strings in
config.js
, even if they are numbers. Therefore, always useparseFloat()
orparseInt()
to convert them to numerical types in your strategy code. For boolean values, be mindful that they might come in as actual booleans or as strings like"true"
or"false"
; handle accordingly. - Custom Parameters: Pair overrides can include any custom settings (key-value pairs) that your strategy is designed to recognize. These do not need to be pre-existing Gunbot parameters.
- GUI Display: The custom override keys you define (e.g.,
MY_CUSTOM_THRESHOLD
) will appear as field labels in the GUI's strategy override section for that pair, allowing for easy adjustment.
By using pair overrides, you can create highly adaptable custom strategies that can be fine-tuned for different market conditions or pairs directly from the Gunbot GUI.