Skip to main content

Filter pairs by current bid-ask spread percentage with AutoConfig

ยท 6 min read

The bid-ask spread, representing the difference between the highest price a buyer is willing to pay (bid) and the lowest price a seller is willing to accept (ask), is a critical indicator of a trading pair's liquidity and transaction costs. Gunbot's AutoConfig feature allows you to filter pairs based on this spread percentage using the minSpreadPct and maxSpreadPct filter types. This helps in selecting pairs that are cost-effective to trade or avoiding those with excessively wide spreads.

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.

Understanding Bid-Ask Spread Percentageโ€‹

The bid-ask spread is a direct measure of market liquidity for a pair.

  • Narrow Spread (Low Percentage): Indicates a liquid market with many participants and tight pricing. This is generally favorable for traders as it means lower costs to get into and out of positions.
  • Wide Spread (High Percentage): Suggests lower liquidity, fewer participants, or higher volatility. Trading such pairs can incur significant costs just to "cross the spread" (i.e., buying at the ask and selling at the bid).

AutoConfig's spread percentage filters allow you to automate pair selection based on this crucial characteristic.

maxSpreadPct Filterโ€‹

The maxSpreadPct filter is commonly used to ensure that AutoConfig only considers pairs with a reasonably tight spread, thus avoiding pairs with potentially high transaction costs or poor liquidity.

Configuration:

{
"liquidPairsOnly": {
"enabled": true,
"type": "addPairs",
"schedule": "*/15 * * * *",
"pairs": {
"exchange": "kraken",
"include": "-EUR"
},
"filters": {
"acceptableSpread": { // Your descriptive name for the filter rule
"filterType": "maxSpreadPct",
// The next key's name is arbitrary; its value is the max percentage.
"maxSpreadAllowed": 0.3 // Pass if spread is LESS than 0.3%
}
// ... other filters like volume or volatility ...
},
"strategy": "spotgrid"
}
}

In the acceptableSpread filter:

  • "filterType": "maxSpreadPct" defines the logic.
  • "maxSpreadAllowed": 0.3: AutoConfig will calculate the current spread percentage for each EUR-quoted pair on Kraken. If ((ask - bid) / bid) * 100 is less than 0.3, this filter rule passes for that pair. Pairs with spreads of 0.3% or wider will fail this filter.

This is very useful for strategies that rely on small profit margins or frequent trading, where minimizing spread costs is essential.

minSpreadPct Filterโ€‹

The minSpreadPct filter is used less frequently for adding pairs but can have niche applications, for example, in strategies that specifically look for wider spreads (perhaps in market-making type scenarios, though AutoConfig itself isn't a market maker) or to identify pairs that might be experiencing unusual conditions. More commonly, it might be used to exclude pairs that are too liquid if a strategy seeks a certain level of inefficiency.

Configuration:

{
"findArbitrageGapsMaybe": { // Highly conceptual example
// ... job settings ...
"filters": {
"minimumSpreadGap": {
"filterType": "minSpreadPct",
"minSpreadRequired": 1.5 // Pass if spread is GREATER than 1.5%
}
}
// ...
}
}

In this conceptual minimumSpreadGap filter, a pair would pass only if its current bid-ask spread percentage is greater than 1.5%.

Key Considerationsโ€‹

  1. Data Source: These filters rely on real-time bid and ask prices from the ticker data fetched by AutoConfig. The accuracy of the spread calculation depends on the freshness and reliability of this data.
  2. Calculation: The standard formula for spread percentage is ((Ask - Bid) / Bid) * 100. Ensure your understanding aligns with how Gunbot might implement this.
  3. Arbitrary Key Name for Value: Similar to volume filters, the key name for the percentage threshold (e.g., maxSpreadAllowed, minSpreadRequired) within the filter rule object is arbitrary. AutoConfig uses the filterType and then the numerical value associated with the other key in that rule. Descriptive names are recommended.
  4. Market Conditions: Spreads can change rapidly, especially during volatile periods or for less liquid pairs. A pair that passes a spread filter now might not pass it a few minutes later. Consider the job's schedule frequency.
  5. Combining with Other Filters: Spread filters are most powerful when used in conjunction with other filters like volume (minVolume24h) and volatility (minVolatilityPct24h, maxVolatilityPct24h). A pair might have a tight spread but extremely low volume, making it still unsuitable.
  6. Zero or Negative Spreads: In rare cases or due to data glitches, bid prices might momentarily exceed ask prices, leading to zero or negative spreads. AutoConfig's handling of such edge cases should be robust (typically treating negative as very tight), but it's a point of awareness.

By using the maxSpreadPct and minSpreadPct filters, you can instruct AutoConfig to be selective about the liquidity conditions of the pairs it interacts with. Prioritizing pairs with tighter spreads generally leads to more efficient trading and better fills, which is crucial for the profitability of many automated strategies.