Skip to main content

Limit active trading pairs per exchange with AutoConfig's maxPairs

ยท 7 min read

When using Gunbot's AutoConfig addPairs jobs to dynamically discover and add new trading opportunities, it's often crucial to control the total number of pairs actively trading on an exchange. This helps manage risk, available capital, and system resources. AutoConfig addresses this with the maxPairs parameter, which sets an upper limit on the number of enabled pairs for a given exchange.

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 maxPairs Parameter: Controlling Exposureโ€‹

The maxPairs parameter serves as a ceiling for the number of trading pairs that an AutoConfig addPairs job will allow to be active simultaneously on a particular exchange. When an addPairs job identifies new pairs that pass its filters, before adding them to your config.js, it first checks how many pairs are already enabled for that exchange.

  • If the number of currently enabled pairs plus the number of new pairs to be added is less than or equal to maxPairs, the new pairs are added.
  • If adding all new qualifying pairs would exceed maxPairs, the job will typically add only enough new pairs to reach the maxPairs limit. It might prioritize which ones to add based on internal logic or the order they were processed, or it might log that not all potential pairs could be added due to the limit.
  • If the number of currently enabled pairs is already at or above maxPairs, no new pairs will be added by that job run, even if they pass all other filters.

This mechanism is crucial for preventing your bot from accumulating an unmanageable number of active trading positions.

Configuration of maxPairsโ€‹

The maxPairs parameter is most commonly configured within the pairs object of an addPairs type AutoConfig job.

Example:

{
"smartPairAdder": {
"enabled": true,
"type": "addPairs",
"schedule": "*/30 * * * *", // Runs every 30 minutes
"strategy": "spotgrid",
"pairs": {
"exchange": "kraken",
"include": "-EUR", // Focus on EUR based pairs
"maxPairs": 15 // User setting: Do not exceed 15 enabled pairs on Kraken
},
"filters": {
"minVolumeEUR": {
"filterType": "minVolume24h", // Ensure volume is in quote currency (EUR here)
"minVolume": 20000 // Minimum 20,000 EUR 24h volume
},
"minPriceMovement": {
"filterType": "minVolatilityPct24h",
"minVolatility": 1.0 // At least 1% price movement
}
}
// ... other job settings like 'overrides' ...
}
}

In the smartPairAdder job:

  • "exchange": "kraken" specifies that this job targets the Kraken exchange.
  • "maxPairs": 15 sets the limit. This job will not allow more than 15 pairs to be enabled on Kraken as a result of its actions. If there are already 12 enabled pairs on Kraken, and this job finds 5 new EUR pairs that pass filters, it will only add 3 of them to reach the 15-pair limit. If there are already 15 or more enabled pairs, it will add none.

Note on Location: While commonly found under pairs: { ... }, some older examples or specific Gunbot versions might have interpreted maxPairs at the top level of the job definition. Always refer to the current Gunbot documentation for the canonical structure. The logic, however, remains the same: it's a per-exchange limit enforced by addPairs jobs.

How maxPairs Interacts with Your Setupโ€‹

  1. Scope: maxPairs is typically enforced per exchange. If you have addPairs jobs for multiple exchanges, each can have its own maxPairs limit.
  2. Counting Enabled Pairs: The job counts pairs in your config.js for the target exchange that have "enabled": true. Manually added or disabled pairs are factored into this count.
  3. Pair Removal: maxPairs itself does not remove pairs. If you are at your maxPairs limit and want to add new ones, you need a separate mechanism or another AutoConfig job (e.g., type removePairs) to disable or remove underperforming existing pairs to make room.
  4. Multiple addPairs Jobs: If you have multiple addPairs jobs for the same exchange, they will all respect the maxPairs limit defined within them. However, they don't coordinate in a sophisticated way beyond checking the current count. The job that runs first and finds qualifying pairs might fill up the slots. Careful scheduling and distinct maxPairs values (if desired for different categories of adds) might be needed.
  5. Dynamic maxPairs: The value for maxPairs can also be a string evaluated as JavaScript if it starts with a leading space. This allows for dynamic limits.
    "pairs": {
    "exchange": "binance",
    "maxPairs": " this.variables.conservativeMode ? 5 : 15 ", // Dynamic limit
    "include": "USDT-"
    }
    This example sets maxPairs to 5 if a global variable conservativeMode is true, otherwise to 15.

Benefits of Using maxPairsโ€‹

  • Capital Allocation: Prevents your trading capital from being spread too thinly across an excessive number of pairs, which can diminish returns per trade or hit exchange minimum trade size issues.
  • Risk Management: Limits your overall market exposure by capping the number of active positions.
  • System Performance: Running strategies on many pairs consumes CPU, memory, and API rate limits. maxPairs helps keep these demands manageable.
  • Focus on Quality: Encourages your filter design to be more selective, as only a limited number of "slots" are available for new pairs.

The maxPairs parameter is a simple but effective tool for maintaining control over the number of active trading pairs when using AutoConfig's addPairs functionality. It's a key component in building a sustainable and manageable automated trading system with Gunbot. Regularly review your maxPairs settings in conjunction with your capital, risk tolerance, and system capacity.