Skip to main content

Dynamically adjust exchange polling delay with AutoConfig jobs

· 4 min read

Gunbot's exchange polling delay controls how often it fetches market data. While you set a default in config.js, AutoConfig jobs can update an exchange's delay value when filters pass.

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.

The Exchange delay Setting in config.js

Each configured exchange has a delay value in milliseconds that controls the pause between market data cycles.

// In config.js
"exchanges": {
"binance": {
"key": "...",
"secret": "...",
"delay": 5, // Polling delay for Binance: 5 seconds
// ...
}
}

Lower delays mean more frequent updates but higher API usage. Higher delays reduce API load but make data less fresh.

AutoConfig's delay Action Parameter

Add a top-level delay key to an AutoConfig job to update the targeted exchange. The job must specify pairs.exchange and pass its filters.

Configuration Example:

{
"binanceDelayManager": {
"enabled": true,
"type": "changeDelay",
"schedule": "*/1 * * * *", // Check every minute
"pairs": {
"exchange": "binance" // This job targets settings for 'binance'
},
"filters": {
"apiIssueFlagIsActive": {
"filterType": "variableExact",
"experiencingApiIssues": true
}
},
"delay": 15000 // User setting: New delay in ms (15 seconds)
// This will update config.exchanges.binance.delay
}
}

If the apiIssueFlagIsActive filter passes, AutoConfig updates config.exchanges.binance.delay to 15000.

Reverting the Delay: Use a second job (or a different filter path) to set the delay back when the condition clears.

{
"binanceDelayNormalizer": {
"enabled": true,
"type": "changeDelay",
"schedule": "*/1 * * * *",
"pairs": { "exchange": "binance" },
"filters": {
"apiIssuesResolved": {
"filterType": "variableExact", // Or variableNotExist if the flag is deleted
"experiencingApiIssues": false
}
},
"delay": 5000 // Set delay back to 5 seconds
}
}

Use Cases for Dynamic Delay Adjustment

  1. API Rate Limit Management: Increase delay when API errors rise to reduce request frequency.
  2. Market-Dependent Update Frequency: Decrease delay cautiously during volatile periods; increase it during quiet markets.
  3. Time-Based Adjustments: Raise delay during expected low liquidity or exchange maintenance windows.
  4. System Load Management: Increase delay if system resources are constrained.

Important Considerations

  • Milliseconds: The delay value is in milliseconds (e.g., 5000 for 5 seconds).
  • Impact on Trading: A high delay can miss entry/exit signals; a low delay can trigger rate limits or bans.
  • Global Effect for the Exchange: The AutoConfig delay action changes the delay for all pairs on that exchange by updating the exchange-level setting in config.js.
  • Dynamic Values: The delay value can be a string evaluated as JavaScript (if it starts with a leading space), allowing dynamic calculations based on this.variables, etc.
    "delay": " (this.variables.apiErrorCount > 5 ? 20000 : 5000) "
  • Reloading config.js: AutoConfig writes these changes to config.js. When Gunbot reloads its configuration, it applies the new delay value.

Dynamically adjusting exchange polling delay is an advanced technique for managing API limits and system load. Use cautious values and revert changes when the triggering condition clears.