From 3d1568783e85378a88dde268b68545f0da968d52 Mon Sep 17 00:00:00 2001 From: mrpabloyeah Date: Sun, 13 Apr 2025 01:39:03 +0200 Subject: [PATCH 1/5] Allow warning messages when starting backtesting --- freqtrade/mixins/logging_mixin.py | 12 ++++++++---- freqtrade/optimize/backtesting.py | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/freqtrade/mixins/logging_mixin.py b/freqtrade/mixins/logging_mixin.py index 58399e738..e9a30d471 100644 --- a/freqtrade/mixins/logging_mixin.py +++ b/freqtrade/mixins/logging_mixin.py @@ -9,8 +9,8 @@ class LoggingMixin: Shows similar messages only once every `refresh_period`. """ - # Disable output completely - show_output = True + # Disable INFO output when False + show_info_output = True def __init__(self, logger, refresh_period: int = 3600): """ @@ -35,6 +35,10 @@ class LoggingMixin: # Log as debug first self.logger.debug(message) - # Call hidden function. - if self.show_output: + + # Determine if this is an INFO level message + is_info_message = getattr(logmethod, "__name__", "") == "info" + + # For INFO messages, respect show_info_output flag + if not is_info_message or self.show_info_output: _log_once(message) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 9326c0840..92a9cf261 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -114,7 +114,7 @@ class Backtesting: """ def __init__(self, config: Config, exchange: Exchange | None = None) -> None: - LoggingMixin.show_output = False + LoggingMixin.show_info_output = False self.config = config self.results: BacktestResultType = get_BacktestResultType_default() self.trade_id_counter: int = 0 @@ -235,7 +235,7 @@ class Backtesting: @staticmethod def cleanup(): - LoggingMixin.show_output = True + LoggingMixin.show_info_output = True enable_database_use() def init_backtest_detail(self) -> None: From 33105a996e63a993acb2235d63753c48b88c4e8b Mon Sep 17 00:00:00 2001 From: mrpabloyeah Date: Sun, 13 Apr 2025 12:27:19 +0200 Subject: [PATCH 2/5] Show only whitelist warnings --- freqtrade/mixins/logging_mixin.py | 12 ++++-------- freqtrade/optimize/backtesting.py | 4 ++-- freqtrade/plugins/pairlist/IPairList.py | 8 ++++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/freqtrade/mixins/logging_mixin.py b/freqtrade/mixins/logging_mixin.py index e9a30d471..58399e738 100644 --- a/freqtrade/mixins/logging_mixin.py +++ b/freqtrade/mixins/logging_mixin.py @@ -9,8 +9,8 @@ class LoggingMixin: Shows similar messages only once every `refresh_period`. """ - # Disable INFO output when False - show_info_output = True + # Disable output completely + show_output = True def __init__(self, logger, refresh_period: int = 3600): """ @@ -35,10 +35,6 @@ class LoggingMixin: # Log as debug first self.logger.debug(message) - - # Determine if this is an INFO level message - is_info_message = getattr(logmethod, "__name__", "") == "info" - - # For INFO messages, respect show_info_output flag - if not is_info_message or self.show_info_output: + # Call hidden function. + if self.show_output: _log_once(message) diff --git a/freqtrade/optimize/backtesting.py b/freqtrade/optimize/backtesting.py index 92a9cf261..9326c0840 100644 --- a/freqtrade/optimize/backtesting.py +++ b/freqtrade/optimize/backtesting.py @@ -114,7 +114,7 @@ class Backtesting: """ def __init__(self, config: Config, exchange: Exchange | None = None) -> None: - LoggingMixin.show_info_output = False + LoggingMixin.show_output = False self.config = config self.results: BacktestResultType = get_BacktestResultType_default() self.trade_id_counter: int = 0 @@ -235,7 +235,7 @@ class Backtesting: @staticmethod def cleanup(): - LoggingMixin.show_info_output = True + LoggingMixin.show_output = True enable_database_use() def init_backtest_detail(self) -> None: diff --git a/freqtrade/plugins/pairlist/IPairList.py b/freqtrade/plugins/pairlist/IPairList.py index 89a9e68cd..dff3e41e4 100644 --- a/freqtrade/plugins/pairlist/IPairList.py +++ b/freqtrade/plugins/pairlist/IPairList.py @@ -237,6 +237,11 @@ class IPairList(LoggingMixin, ABC): :return: the list of pairs the user wants to trade without those unavailable or black_listed """ + + # Save show_output value and set it to True + prev_show_output = self.show_output + self.show_output = True + markets = self._exchange.markets if not markets: raise OperationalException( @@ -277,5 +282,8 @@ class IPairList(LoggingMixin, ABC): if pair not in sanitized_whitelist: sanitized_whitelist.append(pair) + # Return show_output to its previous value + self.show_output = prev_show_output + # We need to remove pairs that are unknown return sanitized_whitelist From 16378d32d72bbdc639cdb9225139a8a4127f1671 Mon Sep 17 00:00:00 2001 From: mrpabloyeah Date: Sun, 13 Apr 2025 13:06:35 +0200 Subject: [PATCH 3/5] Show only selected warnings using the force_show parameter --- freqtrade/mixins/logging_mixin.py | 10 ++++++---- freqtrade/plugins/pairlist/IPairList.py | 17 ++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/freqtrade/mixins/logging_mixin.py b/freqtrade/mixins/logging_mixin.py index 58399e738..168e1515e 100644 --- a/freqtrade/mixins/logging_mixin.py +++ b/freqtrade/mixins/logging_mixin.py @@ -20,21 +20,23 @@ class LoggingMixin: self.refresh_period = refresh_period self._log_cache: TTLCache = TTLCache(maxsize=1024, ttl=self.refresh_period) - def log_once(self, message: str, logmethod: Callable) -> None: + def log_once(self, message: str, logmethod: Callable, force_show: bool = False) -> None: """ Logs message - not more often than "refresh_period" to avoid log spamming Logs the log-message as debug as well to simplify debugging. :param message: String containing the message to be sent to the function. :param logmethod: Function that'll be called. Most likely `logger.info`. + :param force_show: If True, sends the message regardless of show_output value. :return: None. """ - @cached(cache=self._log_cache) def _log_once(message: str): logmethod(message) # Log as debug first self.logger.debug(message) - # Call hidden function. - if self.show_output: + + # Call hidden function if show_output is True or force_show is True + if self.show_output or force_show: _log_once(message) + diff --git a/freqtrade/plugins/pairlist/IPairList.py b/freqtrade/plugins/pairlist/IPairList.py index dff3e41e4..9cb5d7744 100644 --- a/freqtrade/plugins/pairlist/IPairList.py +++ b/freqtrade/plugins/pairlist/IPairList.py @@ -237,11 +237,6 @@ class IPairList(LoggingMixin, ABC): :return: the list of pairs the user wants to trade without those unavailable or black_listed """ - - # Save show_output value and set it to True - prev_show_output = self.show_output - self.show_output = True - markets = self._exchange.markets if not markets: raise OperationalException( @@ -256,6 +251,7 @@ class IPairList(LoggingMixin, ABC): f"Pair {pair} is not compatible with exchange " f"{self._exchange.name}. Removing it from whitelist..", logger.warning, + True, ) continue @@ -263,6 +259,7 @@ class IPairList(LoggingMixin, ABC): self.log_once( f"Pair {pair} is not tradable with Freqtrade. Removing it from whitelist..", logger.warning, + True, ) continue @@ -271,19 +268,21 @@ class IPairList(LoggingMixin, ABC): f"Pair {pair} is not compatible with your stake currency " f"{self._config['stake_currency']}. Removing it from whitelist..", logger.warning, + True, ) continue # Check if market is active market = markets[pair] if not market_is_active(market): - self.log_once(f"Ignoring {pair} from whitelist. Market is not active.", logger.info) + self.log_once( + f"Ignoring {pair} from whitelist. Market is not active.", + logger.info, + True, + ) continue if pair not in sanitized_whitelist: sanitized_whitelist.append(pair) - # Return show_output to its previous value - self.show_output = prev_show_output - # We need to remove pairs that are unknown return sanitized_whitelist From 6fa1133c61b4b3e1a46dcc132ea2b340bdae87f5 Mon Sep 17 00:00:00 2001 From: mrpabloyeah Date: Sun, 13 Apr 2025 13:12:43 +0200 Subject: [PATCH 4/5] Remove space at the end of logging_mixin.py --- freqtrade/mixins/logging_mixin.py | 1 - 1 file changed, 1 deletion(-) diff --git a/freqtrade/mixins/logging_mixin.py b/freqtrade/mixins/logging_mixin.py index 168e1515e..355bc43e8 100644 --- a/freqtrade/mixins/logging_mixin.py +++ b/freqtrade/mixins/logging_mixin.py @@ -39,4 +39,3 @@ class LoggingMixin: # Call hidden function if show_output is True or force_show is True if self.show_output or force_show: _log_once(message) - From e6b5233d2fb50418a1bbb2236ba9c9b21b5e9738 Mon Sep 17 00:00:00 2001 From: mrpabloyeah Date: Sun, 13 Apr 2025 13:25:30 +0200 Subject: [PATCH 5/5] Add space after docstring --- freqtrade/mixins/logging_mixin.py | 1 + 1 file changed, 1 insertion(+) diff --git a/freqtrade/mixins/logging_mixin.py b/freqtrade/mixins/logging_mixin.py index 355bc43e8..91ad2c25e 100644 --- a/freqtrade/mixins/logging_mixin.py +++ b/freqtrade/mixins/logging_mixin.py @@ -29,6 +29,7 @@ class LoggingMixin: :param force_show: If True, sends the message regardless of show_output value. :return: None. """ + @cached(cache=self._log_cache) def _log_once(message: str): logmethod(message)