From e0a06ca454dcb84ecbd8dbec77ef131168536451 Mon Sep 17 00:00:00 2001 From: Stefano Ariestasia Date: Wed, 13 Sep 2023 14:18:07 +0900 Subject: [PATCH] add fulltradesfilter --- .../plugins/pairlist/FullTradesFilter.py | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 freqtrade/plugins/pairlist/FullTradesFilter.py diff --git a/freqtrade/plugins/pairlist/FullTradesFilter.py b/freqtrade/plugins/pairlist/FullTradesFilter.py new file mode 100644 index 000000000..9365abf02 --- /dev/null +++ b/freqtrade/plugins/pairlist/FullTradesFilter.py @@ -0,0 +1,78 @@ +""" +Performance pair list filter +""" +import logging +from typing import Any, Dict, List + +import pandas as pd + +from freqtrade.constants import Config +from freqtrade.exchange.types import Tickers +from freqtrade.persistence import Trade +from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter + + +logger = logging.getLogger(__name__) + + +class FullTradesFilter(IPairList): + + def __init__(self, exchange, pairlistmanager, + config: Config, pairlistconfig: Dict[str, Any], + pairlist_pos: int) -> None: + super().__init__(exchange, pairlistmanager, config, pairlistconfig, pairlist_pos) + + self._minutes = pairlistconfig.get('minutes', 0) + self._min_profit = pairlistconfig.get('min_profit') + + @property + def needstickers(self) -> bool: + """ + Boolean property defining if tickers are necessary. + If no Pairlist requires tickers, an empty List is passed + as tickers argument to filter_pairlist + """ + return False + + def short_desc(self) -> str: + """ + Short allowlist method description - used for startup-messages + """ + return f"{self.name} - Emptying whitelist when trade slots are full." + + @staticmethod + def description() -> str: + return "Emptying whitelist when trade slots are full." + + @staticmethod + def available_parameters() -> Dict[str, PairlistParameter]: + return { + + } + + def filter_pairlist(self, pairlist: List[str], tickers: Tickers) -> List[str]: + """ + Filters and sorts pairlist and returns the allowlist again. + Called on each bot iteration - please use internal caching if necessary + :param pairlist: pairlist to filter or sort + :param tickers: Tickers (from exchange.get_tickers). May be cached. + :return: new allowlist + """ + # Get the trading performance for pairs from database + try: + trades = Trade.get_trades(Trade.is_open.is_(True)).all() + except AttributeError: + # Performancefilter does not work in backtesting. + self.log_once("PerformanceFilter is not available in this mode.", logger.warning) + return pairlist + + # Skip performance-based sorting if no performance data is available + num_open = len(trades) + if num_open == 0: + return pairlist + + max_trades = self._config['max_open_trades'] + + self.log_once(f"Max open trades: {max_trades}, current open trades: {num_open}") + + return pairlist