Skip to main content

Using AutoConfig to Control Pair Settings.

AutoConfig is a versatile feature in Gunbot that enables traders to dynamically adjust their bot configuration based on real-time market conditions or custom logic.

AutoConfig allows Gunbot users to automate config adjustments without manual intervention. By defining specific conditions and actions within the autoconfig.json file, traders can set up jobs that monitor the market and modify strategy parameters on the fly.

This guide focuses on concise jobs to manage a small number of pair settings, using custom code to reach dynamic behavior. The goal is to show specific usage examples that might not be obvious from the documentation.

Custom javascript code can be very easy, like in the first example, or rather complex, like in the second example. It may look intimidating at first, but when you can put an automation idea in words, then getting the code for it is often not difficult at all, using modern AI tools like chatGPT.

Before You Start

To use these examples:

  1. store them in the autoconfig.json file, either using the built-in code editor or a text editor of your choice. Technically it's possible to use our visual editor to create these jobs, but in reality it is just easier to do it a code editor.
  2. modify them where needed
  3. ensure that AutoConfig itself is enabled, you can toggle the enabled box on the AutoConfig page to do this.

First Example: Dynamic Bounds Adjustment for Aggressive Quanta G-Type Strategy

Scenario Overview

Let's say you're running an aggressive quanta G-type strategy and wish to dynamically adjust the strategy's bounds continually, to a zone that's 10% 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 set to always pass, indicating no specific conditions need to be met for the job to execute. When all filters in an AutoConfig job pass, then it will proceed with it's action - in this case placing override values for the bounds.
  • overrides: Dynamically adjusts the UPPER_BOUND and LOWER_BOUND based on the EMA1 value of each pair. This is done by multiplying EMA1 by 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 manageOverrides job type is suitable for editing pair override settings, with low overhead.

Explanation of Custom Code

The custom code within "overrides" dynamically calculates the bounds. This approach allows for real-time adjustment of strategy parameters, ensuring the strategy remains optimal under varying market conditions.

It does this by simply placing calculated values based on simple math using EMA as input.

Second Example: Volatility Protection

Scenario Overview

Let's say you want to disable buying for specified pairs, during periods of high market volatility. Using a custom definition and threshold values for high volatility.

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-ETH and USDT-BTC on binance.
  • filters: Uses a custom filter that always passes, because we just always want to place BUY_ENABLED with its dynamic value.
  • 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 manageOverrides job type is suitable for editing pair override settings, with low overhead.

Code Explanation and Adjustment Guide

This is a rather complicated example, just to show how far you can go in defining your own logic.

Functionality

This code:

  • Verifies if candleslow and candleshigh arrays are initialized and contain at least one entry.
  • Retrieves the latest 96 entries (or all entries if fewer than 96 exist) from both arrays. For strategies utilizing 15-minute candle periods, this corresponds to the last 24 hours.
  • Computes the average of these entries.
  • Checks for any entry exceeding 10% above or below the calculated average.
  • Returns false if such an entry is found; otherwise, it returns true. If the arrays are undefined or empty, it also returns true.

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 -96 to -50.
    • Code Snippet: Replace .slice(-96) with .slice(-50).

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 *.

To Adjust the Number of Entries

  • Search for .slice(-96) in your code.
  • Replace -96 with -50 to 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.1 to 0.05 for a 5% threshold, changing the code to > 0.05 *.

Custom Code Requirements

When integrating custom code within AutoConfig jobs, it is essential to 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.