Fix / improve types

This commit is contained in:
Matthias
2024-04-17 20:58:58 +02:00
parent 5eeb96fa96
commit 82482ec159
2 changed files with 5 additions and 3 deletions

View File

@@ -141,7 +141,7 @@ class FreqtradeBot(LoggingMixin):
# Initialize protections AFTER bot start - otherwise parameters are not loaded. # Initialize protections AFTER bot start - otherwise parameters are not loaded.
self.protections = ProtectionManager(self.config, self.strategy.protections) self.protections = ProtectionManager(self.config, self.strategy.protections)
def log_took_too_long(duration: int, time_limit: int): def log_took_too_long(duration: float, time_limit: float):
logger.warning( logger.warning(
f"Strategy analysis took {duration:.2f}, which is 25% of the timeframe. " f"Strategy analysis took {duration:.2f}, which is 25% of the timeframe. "
"This can lead to delayed orders and missed signals." "This can lead to delayed orders and missed signals."

View File

@@ -13,7 +13,8 @@ class MeasureTime:
Measure the time of a block of code and call a callback if the time limit is exceeded. Measure the time of a block of code and call a callback if the time limit is exceeded.
""" """
def __init__(self, callback: Callable[[int, int], None], time_limit: int, ttl: int = 3600 * 4): def __init__(
self, callback: Callable[[float, float], None], time_limit: float, ttl: int = 3600 * 4):
""" """
:param callback: The callback to call if the time limit is exceeded. :param callback: The callback to call if the time limit is exceeded.
This callback will be called once every "ttl" seconds, This callback will be called once every "ttl" seconds,
@@ -21,10 +22,11 @@ class MeasureTime:
"time limit" - representing the passed in time limit. "time limit" - representing the passed in time limit.
:param time_limit: The time limit in seconds. :param time_limit: The time limit in seconds.
:param ttl: The time to live of the cache in seconds. :param ttl: The time to live of the cache in seconds.
defaults to 4 hours.
""" """
self._callback = callback self._callback = callback
self._time_limit = time_limit self._time_limit = time_limit
self.__cache = TTLCache(maxsize=1, ttl=ttl) self.__cache: TTLCache = TTLCache(maxsize=1, ttl=ttl)
def __enter__(self): def __enter__(self):
self._start = time.time() self._start = time.time()