Skip to main content

Filter pairs by specific min/max price points with AutoConfig

ยท 6 min read

When selecting trading pairs with Gunbot's AutoConfig, particularly for addPairs jobs, you might want to target or avoid pairs based on their absolute current price. For instance, you might prefer to avoid very low-priced "penny stock" style cryptocurrencies or, conversely, target only those below a certain price point. AutoConfig provides minPrice and maxPrice filter types to achieve this.

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.

Filtering by Absolute Price Levelsโ€‹

The minPrice and maxPrice filters in AutoConfig operate on the current price of a pair as obtained from the latest ticker data snapshot. They allow you to define acceptable price ranges for pairs to be considered by an AutoConfig job.

  1. filterType: "minPrice":

    • Purpose: Passes if the pair's current relevant price is greater than or equal to the specified minimum value.
    • Use Case: To avoid extremely low-priced coins (e.g., those priced at fractions of a cent) if they don't fit your strategy or risk profile. Can also be used to target coins that have reached a certain minimum price level.
  2. filterType: "maxPrice":

    • Purpose: Passes if the pair's current relevant price is less than or equal to the specified maximum value.
    • Use Case: To avoid very high-priced coins if your capital per trade is limited, or if your strategy is designed for coins within a certain price ceiling. Can also be used to specifically target lower-priced assets.

Configurationโ€‹

These filters are defined within an AutoConfig job's filters (or filters2, etc.) object:

{
"priceRangeSelector": {
"enabled": true,
"type": "addPairs",
"schedule": "0 * * * *", // Hourly
"pairs": {
"exchange": "binance",
"include": "-USDT"
},
"filters": {
"abovePennyStockLevel": { // Rule name (arbitrary)
"filterType": "minPrice",
// The next key's name is arbitrary; its value is the price threshold.
"minimumAcceptablePrice": 0.01 // Price in USDT
},
"notTooExpensive": { // Rule name (arbitrary)
"filterType": "maxPrice",
"maximumAcceptablePrice": 100.00 // Price in USDT
}
// ... other filters like volume, spread ...
},
"strategy": "spotgrid"
}
}

In the priceRangeSelector job:

  • The abovePennyStockLevel filter uses minPrice. It will pass for a pair if its current price (e.g., ask price from the ticker) is 0.01 USDT or higher.
  • The notTooExpensive filter uses maxPrice. It will pass if the pair's current price is 100.00 USDT or lower.
  • For a pair to be added by this job, it must pass both these price filters (and any other filters defined in the set), meaning its price must be between $0.01 and $100.00 USDT.

Key Considerationsโ€‹

  1. Price Source:

    • For addPairs jobs evaluating new market tickers, the price used for comparison is typically the current ask price from the ticker data (this.tickers[jobName][...][pairName].ask).
    • For jobs operating on existing pairs (like manageOverrides or removePairs), the price might be the bid price or last traded price from the ticker data, depending on the context and specific internal logic of the filter for that job type. It's always based on the latest available ticker information.
    • On exchanges like Huobi where ask/bid might not be directly available in all ticker fetches, it might use last price.
  2. Quote Currency: The price values you specify (e.g., 0.01, 100.00) are always in the quote currency of the pair being evaluated.

    • For BTC-USDT, the thresholds are in USDT.
    • For ETH-BTC, the thresholds would be in BTC. You must adjust your price thresholds accordingly if your pairs.include covers pairs with different quote currencies.
  3. Arbitrary Key Name for Value: In the filter definition (e.g., { "filterType": "minPrice", "myKey": 0.01 }), the key name for the price threshold (myKey in this snippet) is arbitrary and for your description only. AutoConfig uses the filterType and then expects the numerical value associated with the other key in that filter rule's object.

  4. Combining Filters: minPrice and maxPrice are often used together to define a specific price range, as shown in the example. They are also typically combined with other filters like volume (minVolume24h) and spread (maxSpreadPct) for more robust pair selection.

  5. Dynamic Thresholds via Custom Filters: If you need the price thresholds themselves to be dynamic (e.g., based on a global variable or acUserData.json), these built-in minPrice/maxPrice filters might not directly support evaluated strings for their threshold values. In such cases, a custom JavaScript filter would be more appropriate, where you can write logic like:

    // Custom filter script
    // const latestAsk = this.tickers[jobName][this.tickers[jobName].length-1][this.pairName].ask;
    // const minPriceThreshold = this.variables.currentMinPriceTarget || 0.005;
    // return latestAsk >= minPriceThreshold;

Using minPrice and maxPrice filters allows you to easily incorporate absolute price level criteria into your AutoConfig job's decision-making process, helping to refine pair selection to tranches that fit your strategy's capital requirements or risk preferences.