In Gunbot's AutoConfig, you often need to apply specific actions or logic only to trading pairs where you currently have an existing investment, commonly referred to as holding a "bag" of the quote currency. While not always a direct top-level parameter named pairs.bag
in all filter types, the concept of checking for a bag (i.e., this.pair.quoteBalance > 0
and typically above MIN_VOLUME_TO_SELL
) is a crucial conditional element, often implemented within custom
filters or as an implicit part of certain specialized built-in filters when targeting pairs for actions like manageOverrides
or changeStrategy
.
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 Concept of "Holding a Bag"​
In trading, "holding a bag" means you've bought an asset (the quote currency of a pair, e.g., ETH in USDT-ETH) and are currently holding it, hoping its value will increase so you can sell it for a profit in the base currency (USDT in this case).
AutoConfig jobs, particularly manageOverrides
or changeStrategy
, often need to differentiate their actions based on whether such a bag exists for a pair. For example:
- You wouldn't enable
DOUBLE_UP
(DCA) overrides if you don't have an initial bag to average down. - You'd only apply
STOP_LIMIT
settings if you actually hold the asset to protect. - You might switch to a "take profit" strategy only once a bag has been acquired.
Checking for a Bag in AutoConfig Filters​
While some specific job types or older AutoConfig versions might have had a more direct pairs.bag: true
parameter as a simple boolean check, the most robust and universally applicable method to check if a significant bag exists (i.e., more than dust and enough to make a sell order) is often through a custom
JavaScript filter.
This custom filter would typically inspect:
this.pair.quoteBalance
: The amount of the quote currency Gunbot's ledger says it holds for the pair.this.pair.Ask
orthis.pair.Last
: The current price to value thequoteBalance
.MIN_VOLUME_TO_SELL
(MVTS): The minimum value (in base currency) of a sell order, defined in the pair's strategy. A bag is generally only considered significant if its value exceeds MVTS.
Custom Filter Example to Check for a Bag:
{
"manageActiveBagsJob": {
"enabled": true,
"type": "manageOverrides",
"schedule": "*/5 * * * *",
"pairs": {
"exchange": "binance",
"include": "-USDT"
},
"filters": {
"pairHasSignificantBag": {
"filterType": "custom",
"script": " const pairData = this.pair; \n const pairName = this.pairName; \n const exchangeName = this.exchangeName; \n \n if (!pairData || typeof pairData.quoteBalance !== 'number' || typeof pairData.Ask !== 'number') { \n // console.log(pairName + ': Insufficient ledger data to determine bag status.'); \n return false; \n } \n \n const quoteBalance = pairData.quoteBalance; \n const currentAskPrice = pairData.Ask; \n \n // Get MIN_VOLUME_TO_SELL (MVTS) from the effective strategy for the pair \n let mvts = 0.0005; // Default low value \n const strategyName = this.config.pairs[exchangeName]?.[pairName]?.strategy; \n if (strategyName) { \n mvts = this.config.pairs[exchangeName]?.[pairName]?.override?.MIN_VOLUME_TO_SELL || \n this.config.strategies[strategyName]?.MIN_VOLUME_TO_SELL || \n mvts; \n } \n \n const bagValueInBase = quoteBalance * currentAskPrice; \n \n if (quoteBalance > 0 && bagValueInBase >= mvts) { \n console.log(pairName + ': Has significant bag (Value: ' + bagValueInBase.toFixed(4) + ' >= MVTS: ' + mvts + '). Filter passes.'); \n return true; \n } \n \n // console.log(pairName + ': No significant bag or data missing.'); \n return false; "
}
},
"overrides": { // Apply these overrides only to pairs with bags
"SELL_ENABLED": true, // Example: Ensure selling is enabled
"STOP_LIMIT": 5 // Set a stop-loss
}
}
}
In the pairHasSignificantBag
custom filter:
- It safely accesses
this.pair.quoteBalance
andthis.pair.Ask
. - It retrieves the
MIN_VOLUME_TO_SELL
(MVTS) for the pair, looking first in pair overrides, then in the base strategy definition, and using a small default if not found. - It calculates the current bag's value in the base currency (
bagValueInBase
). - The filter returns
true
ifquoteBalance
is positive ANDbagValueInBase
is greater than or equal tomvts
.
Note on pairs.bag
as a direct parameter:
Some AutoConfig job types or configurations, especially in removePairs
(like pairs.noBag
), might have a more direct boolean parameter named bag
or noBag
. For example, removePairs
might have "bag": true
as a condition within its pairs
object to specifically target removing pairs that do have a bag (a less common scenario for removal, but possible for specific cleanup tasks if combined with other very precise filters). Always refer to the specific documentation for the job type you are using if you expect a direct bag: true/false
key. The custom filter method above is generally more universally adaptable for manageOverrides
or changeStrategy
when you need to confirm a bag's existence.
Use Cases for Targeting Pairs with Bags​
- DCA Management: Apply
DOUBLE_UP
related overrides only ifthis.pair.quoteBalance > 0
. - Stop-Loss Activation: Set or adjust
STOP_LIMIT_PERCENT
only for pairs where you have an active position. - Profit-Taking Adjustments: If a pair has a bag and
this.pair.profit
is high, switch to more aggressive profit-taking overrides. - Strategy Transitions: Move a pair from an "accumulation" strategy to a "distribution" or "sell-off" strategy once a bag is acquired.
- Reversal Trading Logic: If a pair is in
this.pair.reversal === true
(meaning it's trying to sell off a bag after a stop-loss or manual sell), apply specific overrides to facilitate this.
Key Considerations​
- Ledger Data Accuracy: The reliability of this filtering depends on Gunbot's ledger (
this.pair
) being up-to-date and accurate. - MVTS Importance: The
MIN_VOLUME_TO_SELL
setting is crucial for distinguishing between a significant bag and mere exchange dust. Ensure it's configured sensibly in your strategies. - Combining with Other Conditions: Checking for a bag is usually one part of a more complex condition. For example, "if pair has a bag AND profit > X% AND no open sell orders, then apply Y overrides."
pairs.noBag
inremovePairs
: This is the inverse concept, used to prevent removal if a bag exists. The current article focuses on targeting pairs because they have a bag for other actions likemanageOverrides
.
Using the concept of pairs.bag
(whether through a direct parameter if available for your specific job type/filter, or more commonly via a custom script checking this.pair.quoteBalance
against MVTS) allows your AutoConfig jobs to be highly context-aware, applying specific logic only when and where it's most relevant—to the pairs you are actively invested in.