Using AutoConfig to Control Pair Settings in Gunbot
AutoConfig lets you adjust Gunbot configuration based on market conditions or custom logic. Define conditions and actions in autoconfig.json to automate strategy parameter updates.
This guide focuses on concise jobs that manage a small number of pair settings and demonstrate specific, less obvious examples.
Info
AutoConfig jobs are defined in a JSON file (autoconfig.json) and can be used to automate various aspects of your Gunbot trading strategy, such as changing settings based on market indicators or a schedule.
Custom JavaScript can be simple (first example) or complex (second example). If you can describe the automation clearly, you can usually translate it into code.
Before You Start
To use these examples:
- Store them in
autoconfig.jsonusing the built-in code editor or a text editor. The visual editor can create jobs, but a code editor is usually simpler. - Modify them where needed.
- Ensure AutoConfig is enabled (toggle the enabled box on the AutoConfig page).
First Example: Dynamic Bounds Adjustment for Aggressive Quanta G-Type Strategy
Scenario Overview
Assume you're running an aggressive Quanta G-type strategy and want bounds set to a 10% band around an EMA.
autoconfig.json Configuration
{
"ema-bounds": {
"pairs": {
"exclude": "",
"include": "-",
"exchange": "binance"
},
"filters": {
"alwaysPasses": {
"type": "custom",
"target": " true"
}
},
"overrides": {
"UPPER_BOUND": " this.pair.ema1 * 1.1",
"LOWER_BOUND": " this.pair.ema1 * 0.9"
},
"clearOverrides": false,
"schedule": "0 */4 * * *",
"type": "manageOverrides",
"debug": false,
"enabled": true
}
}
Breakdown of Key Components
- pairs: Targets all pairs on Binance by including those with a "-" sign.
- filters: A custom filter that always passes, so the job always runs and places override values for the bounds.
- overrides: Dynamically adjusts the
UPPER_BOUNDandLOWER_BOUNDbased on theEMA1value of each pair. This is done by multiplyingEMA1by 1.1 for the upper bound and 0.9 for the lower bound. - schedule: The job runs every 4 hours, as specified by the cron notation
0 */4 * * *. - type: The
manageOverridesjob type is suitable for editing pair override settings, with low overhead.
Explanation of Custom Code
The custom code in "overrides" calculates bounds from EMA values so the strategy updates as EMA changes.
Second Example: Volatility Protection
Scenario Overview
Assume you want to disable buying for specific pairs during high volatility using a custom threshold.
autoconfig.json Configuration
{
"volatility-protection": {
"pairs": {
"exclude": "",
"include": "USDT-ETH,USDT-BTC",
"exchange": "binance"
},
"filters": {
"alwaysPasses": {
"type": "custom",
"target": " true"
}
},
"overrides": {
"BUY_ENABLED": " Array.isArray(this.pair.candleslow) && Array.isArray(this.pair.candleshigh) && !([...(this.pair.candleslow || []).slice(-96), ...(this.pair.candleshigh || []).slice(-96)].some(val => Math.abs(val - ([...(this.pair.candleslow || []).slice(-96), ...(this.pair.candleshigh || []).slice(-96)].reduce((sum, n) => sum + n, 0) / [...(this.pair.candleslow || []).slice(-96), ...(this.pair.candleshigh || []).slice(-96)].length)) > 0.1 * ([...(this.pair.candleslow || []).slice(-96), ...(this.pair.candleshigh || []).slice(-96)].reduce((sum, n) => sum + n, 0) / [...(this.pair.candleslow || []).slice(-96), ...(this.pair.candleshigh || []).slice(-96)].length)))"
},
"clearOverrides": false,
"schedule": "* * * * *",
"type": "manageOverrides",
"debug": false,
"enabled": true
}
}
Detailed Breakdown
- pairs: Specifies which pairs the job applies to, in this case,
USDT-ETHandUSDT-BTConbinance. - filters: A custom filter that always passes so
BUY_ENABLEDis always updated. - overrides: Contains complex custom code designed to disable buying if the market volatility exceeds 10% based on the analysis of candle high and low data.
- schedule: The job runs every minute, as specified by the cron notation
* * * * *. - type: The
manageOverridesjob type is suitable for editing pair override settings, with low overhead.
Code Explanation and Adjustment Guide
This example is intentionally complex to show the range of custom logic you can implement.
Functionality
This code:
- Verifies if
candleslowandcandleshigharrays are initialized and contain at least one entry. - Retrieves the latest 96 entries (or all entries if fewer than 96 exist) from both arrays. With 15-minute candles, this is the last 24 hours.
- Computes the average of these entries.
- Checks for any entry exceeding 10% above or below the calculated average.
- Returns
falseif such an entry is found; otherwise, it returnstrue. If the arrays are undefined or empty, it also returnstrue.
Adjusting Threshold Values
Change the Number of Latest Entries
To alter the count of the latest entries evaluated:
- The default setting considers the last 96 entries. Modify this by adjusting the
.slice(-96)portion in the code.- Example: For the last 50 entries, change
-96to-50. - Code Snippet: Replace
.slice(-96)with.slice(-50).
- Example: For the last 50 entries, change
Change the Percentage for Significant Deviation
To modify the threshold for significant deviation:
- Currently set at 10% (notated as 0.1). To change this, substitute 0.1 with the decimal form of the desired percentage.
- Example: For a 5% threshold, use
0.05. - Code Snippet: Replace
> 0.1 *with> 0.05 *.
- Example: For a 5% threshold, use
To Adjust the Number of Entries
- Search for
.slice(-96)in your code. - Replace
-96with-50to consider the latest 50 entries, resulting in.slice(-50).
To Modify the Deviation Threshold
- Find the
> 0.1 *in your code, indicating the 10% threshold. - Adjust
0.1to0.05for a 5% threshold, changing the code to> 0.05 *.
Custom Code Requirements
When integrating custom code within AutoConfig jobs, adhere to the following requirements:
- Valid JavaScript: The custom code must be syntactically valid JavaScript to ensure proper execution and compatibility.
- Evaluates to Usable Value: The code must evaluate to a usable value, such as
true,false, or a numerical value. It is also permissible to utilize self-invoking functions to achieve the desired outcome. - Leading Space Requirement: Custom code entries must commence with a leading space. This convention signals the autoconfiguration system to treat the subsequent text as code, thereby triggering its evaluation to determine the output.
- Single Line Format: The custom code must be encapsulated in a single line. This is crucial because JSON does not support multi-line strings, and ensuring the code is on one line facilitates seamless integration within JSON objects or arrays.
- Enclosure in Double Quotes: The entire custom code snippet must be enclosed within double quotes (" "). This is a standard practice in JSON to denote string values, making it necessary for the code to be recognized correctly within the JSON structure.
- Use Single Quotes for Internal Strings: Since the custom code is enclosed in double quotes, any string literals within the code itself must use single quotes (' ') to avoid conflicts with the JSON string delimiters. This ensures that the code remains valid and interpretable both as JavaScript and within the JSON structure.