Add tests for pairlock

This commit is contained in:
Matthias
2020-10-17 11:40:01 +02:00
parent e513871fd5
commit 7caa6cfe31
3 changed files with 60 additions and 12 deletions

View File

@@ -678,11 +678,23 @@ class PairLock(_DECL_BASE):
active = Column(Boolean, nullable=False, default=True)
def __repr__(self):
lock_time = self.open_date.strftime(DATETIME_PRINT_FORMAT)
lock_end_time = self.open_date.strftime(DATETIME_PRINT_FORMAT)
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})')
@staticmethod
def lock_pair(pair: str, until: datetime, reason: str = None) -> None:
lock = PairLock(
pair=pair,
lock_time=datetime.now(timezone.utc),
lock_end_time=until,
reason=reason,
active=True
)
PairLock.session.add(lock)
PairLock.session.flush()
@staticmethod
def get_pair_locks(pair: str, now: Optional[datetime] = None) -> List['PairLock']:
"""

View File

@@ -287,15 +287,7 @@ class IStrategy(ABC):
:param until: datetime in UTC until the pair should be blocked from opening new trades.
Needs to be timezone aware `datetime.now(timezone.utc)`
"""
lock = PairLock(
pair=pair,
lock_time=datetime.now(timezone.utc),
lock_end_time=until,
reason=reason,
active=True
)
PairLock.session.add(lock)
PairLock.session.flush()
PairLock.lock_pair(pair, until, reason)
def unlock_pair(self, pair: str) -> None:
"""