Skip to main content

Use 'resetPairVariable' for pairs failing AutoConfig job filters

ยท 7 min read

Gunbot's AutoConfig provides fine-grained control over per-pair variables, not only when pairs pass filters (using setPairVariable) but also when they fail them. The resetPairVariable action object within an AutoConfig job definition is triggered for each pair that is evaluated by the job but does not meet the criteria of the job's main filters (or filters2, etc.). This allows you to explicitly manage the state of non-qualifying pairs.

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.

setPairVariable vs. resetPairVariable for Individual Pairsโ€‹

When an AutoConfig job (e.g., of type manageOverrides) iterates through a list of pairs defined by pairs.include and pairs.exclude:

  • For each pair, it evaluates the conditions in the filters (and filters2, etc.) objects.
  • If a pair passes all conditions in at least one filter set:
    • The job's main action (e.g., applying overrides) is performed for that pair.
    • The setPairVariable block, if present, is executed for that pair, updating its specific variables.
  • If a pair fails to pass all conditions in any filter set:
    • The job's main action is not performed for that pair.
    • The resetPairVariable block, if present, is executed for that pair, allowing you to set or update its specific variables to reflect its "non-passing" status.

This conditional execution based on filter outcome per pair makes resetPairVariable a precise tool for managing states.

Configuration Exampleโ€‹

Imagine an AutoConfig job that identifies "hot" pairs based on high volatility and volume. If a pair is "hot," it sets a per-pair variable isActiveTrend to true. If a previously "hot" pair no longer meets these criteria, its isActiveTrend flag should be set to false.

{
"trendStatusManager": {
"enabled": true,
"type": "manageOverrides2", // Type allows iteration over existing pairs and collects tickers
"schedule": "*/10 * * * *",
"pairs": {
"exchange": "binance",
"include": "USDT-" // Consider all USDT pairs
},
"filters": { // Conditions for a pair to be considered in an "active trend"
"highVol": {
"filterType": "minVolume24h",
"minVol": 2000000
},
"highVolatility": {
"filterType": "minVolatilityPct24h",
"minVolatility": 5
}
},
"setPairVariable": { // For pairs PASSING the filters
"isActiveTrend": true,
"trendStartTime": " new Date().getTime() " // Record when trend started for this pair
},
"resetPairVariable": { // User setting: For pairs FAILING the filters
"isActiveTrend": false
// We might choose not to clear 'trendStartTime' here, or set it to null,
// depending on whether we want to remember when it was last active.
}
// This job might not apply any 'overrides' if its only goal is variable management.
}
}

In the trendStatusManager job:

  • It iterates through all USDT pairs on Binance.
  • For each pair:
    • If it has volume > 2M AND volatility > 5% (passes filters):
      • setPairVariable executes: isActiveTrend for that pair becomes true, and trendStartTime is updated.
    • If it does NOT meet both conditions (fails filters):
      • resetPairVariable executes: isActiveTrend for that pair becomes false.

This ensures that the isActiveTrend variable for each pair accurately reflects its current status based on the latest filter evaluation.

Dynamic Values in resetPairVariableโ€‹

Values in resetPairVariable can also be dynamic JavaScript expressions (string starting with a leading space), accessing context like this.pair, this.variables, etc.

"resetPairVariable": {
"failedFilterStreak": " ( (this.pairVariables[this.exchangeName]?.[this.pairName]?.failedFilterStreak || 0) + 1 ) ",
"reasonForInactive": " 'Volume below threshold at ' + new Date().toLocaleTimeString() "
}
  • failedFilterStreak: Increments a counter specific to this pair each time it fails the job's main filters.
  • reasonForInactive: Stores a descriptive string for why the pair is now considered inactive by this job. (Note: this is a simplified example; determining the exact failing filter rule to populate this dynamically from within resetPairVariable itself is complex. Usually, the reason is implicit by the job's design.)

When using this.pair in resetPairVariable expressions, remember that the pair failed the main filters. So, data in this.pair reflects its state at the time of failure, which can still be useful for logging or setting specific "failure state" variables.

Use Cases for resetPairVariableโ€‹

  1. Clearing Status Flags: If setPairVariable sets pairState: "active_buy_signal", resetPairVariable can set pairState: "monitoring" when the buy signal conditions are no longer met for that pair.
  2. Decrementing or Resetting Counters: If setPairVariable increments successiveBuysForPair, resetPairVariable might reset it to 0 if the buy condition chain is broken.
  3. Managing Cooldowns: While cooldowns are often managed by checking time since last action, resetPairVariable could clear a isInCooldown: true flag if other conditions allow the cooldown to end prematurely.
  4. Maintaining Accurate State: Ensures that per-pair variables don't remain "stuck" in a state that's no longer valid because the pair ceased to meet the criteria that initially set that state.
  5. Logging or Tagging Non-Qualifying Pairs: You could use resetPairVariable to tag pairs that are consistently failing important filters, perhaps for later manual review or delisting by another job.

Key Differences and Considerationsโ€‹

  • Execution Condition: setPairVariable acts on filter pass (per pair); resetPairVariable acts on filter fail (per pair).
  • Mutually Exclusive per Pair: For any given pair during a single job run, either setPairVariable or resetPairVariable (or neither, if the job has neither block) will execute, but not both.
  • No Global Fallback: Unlike resetVariable (for global vars) which can act if no pairs at all pass a job's filters, resetPairVariable is evaluated individually for each pair that fails the filters, provided that pair was in the initial list processed by the job.
  • Purpose: setPairVariable usually defines an "active" or "target" state. resetPairVariable usually defines a "default", "inactive", or "failure follow-up" state for specific pairs.

The resetPairVariable action complements setPairVariable by providing a robust way to manage the lifecycle and state of individual trading pairs within AutoConfig. It ensures that per-pair variables accurately reflect whether a pair currently meets a job's primary conditions or not, leading to more precise and reliable automations.