diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index bc5ef961a..04f1d67b2 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -896,7 +896,7 @@ class PairLock(_DECL_BASE): lock_time = self.lock_time.strftime(DATETIME_PRINT_FORMAT) lock_end_time = self.lock_end_time.strftime(DATETIME_PRINT_FORMAT) return (f'PairLock(id={self.id}, pair={self.pair}, lock_time={lock_time}, ' - f'lock_end_time={lock_end_time})') + f'lock_end_time={lock_end_time}, reason={self.reason}, active={self.active})') @staticmethod def query_pair_locks(pair: Optional[str], now: datetime) -> Query: @@ -905,7 +905,6 @@ class PairLock(_DECL_BASE): :param pair: Pair to check for. Returns all current locks if pair is empty :param now: Datetime object (generated via datetime.now(timezone.utc)). """ - filters = [PairLock.lock_end_time > now, # Only active locks PairLock.active.is_(True), ] diff --git a/freqtrade/persistence/pairlock_middleware.py b/freqtrade/persistence/pairlock_middleware.py index 6e0164182..386c3d1d7 100644 --- a/freqtrade/persistence/pairlock_middleware.py +++ b/freqtrade/persistence/pairlock_middleware.py @@ -113,13 +113,26 @@ class PairLocks(): """ if not now: now = datetime.now(timezone.utc) - logger.info(f"Releasing all locks with reason \'{reason}\'.") - locks = PairLocks.get_all_locks() - for lock in locks: - if lock.reason == reason: - lock.active = False + + def local_unlock(lock): + lock.active = False + if PairLocks.use_db: + # used in live modes + logger.info(f"Releasing all locks with reason \'{reason}\':") + filters = [PairLock.lock_end_time > now, + PairLock.active.is_(True), + PairLock.reason == reason + ] + locks = PairLock.query.filter(*filters) + for lock in locks: + logger.info(f"Releasing lock for \'{lock.pair}\' with reason \'{reason}\'.") + lock.active = False PairLock.query.session.commit() + else: + # no logging in backtesting to increase speed + locks = filter(lambda reason: reason == reason, PairLocks.locks) + locks = map(local_unlock, locks) @staticmethod def is_global_lock(now: Optional[datetime] = None) -> bool: