removed wrong use of map and filter function

This commit is contained in:
incrementby1 2021-10-28 23:29:26 +02:00
parent 02e69e1667
commit 658006e7ee

View File

@ -114,9 +114,6 @@ class PairLocks():
if not now: if not now:
now = datetime.now(timezone.utc) now = datetime.now(timezone.utc)
def local_unlock(lock):
lock.active = False
if PairLocks.use_db: if PairLocks.use_db:
# used in live modes # used in live modes
logger.info(f"Releasing all locks with reason \'{reason}\':") logger.info(f"Releasing all locks with reason \'{reason}\':")
@ -126,13 +123,15 @@ class PairLocks():
] ]
locks = PairLock.query.filter(*filters) locks = PairLock.query.filter(*filters)
for lock in locks: for lock in locks:
logger.info(f"Releasing lock for \'{lock.pair}\' with reason \'{reason}\'.") logger.info(f"Releasing lock for {lock.pair} with reason \'{reason}\'.")
lock.active = False lock.active = False
PairLock.query.session.commit() PairLock.query.session.commit()
else: else:
# no logging in backtesting to increase speed # used in backtesting mode; don't show log messages for speed
locks = filter(lambda reason: reason == reason, PairLocks.locks) locks = PairLocks.get_locks(None)
locks = map(local_unlock, locks) for lock in locks:
if lock.reason == reason:
lock.active = False
@staticmethod @staticmethod
def is_global_lock(now: Optional[datetime] = None) -> bool: def is_global_lock(now: Optional[datetime] = None) -> bool:
@ -159,7 +158,9 @@ class PairLocks():
@staticmethod @staticmethod
def get_all_locks() -> List[PairLock]: def get_all_locks() -> List[PairLock]:
"""
Return all locks, also locks with expired end date
"""
if PairLocks.use_db: if PairLocks.use_db:
return PairLock.query.all() return PairLock.query.all()
else: else: