From 845f960a4e10ee46b188aab47cabcc931279047b Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 24 Apr 2022 11:24:15 +0200 Subject: [PATCH] realign pairlock naming to side --- freqtrade/persistence/migrations.py | 6 +++--- freqtrade/persistence/models.py | 4 ++-- freqtrade/persistence/pairlock_middleware.py | 6 +++--- tests/test_freqtradebot.py | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/freqtrade/persistence/migrations.py b/freqtrade/persistence/migrations.py index eff2d69f3..93c70b70d 100644 --- a/freqtrade/persistence/migrations.py +++ b/freqtrade/persistence/migrations.py @@ -219,16 +219,16 @@ def migrate_pairlocks_table( drop_index_on_table(engine, inspector, pairlock_back_name) - direction = get_column_def(cols, 'direction', "'*'") + side = get_column_def(cols, 'side', "'*'") # let SQLAlchemy create the schema as required decl_base.metadata.create_all(engine) # Copy data back - following the correct schema with engine.begin() as connection: connection.execute(text(f"""insert into pairlocks - (id, pair, direction, reason, lock_time, + (id, pair, side, reason, lock_time, lock_end_time, active) - select id, pair, {direction} direction, reason, lock_time, + select id, pair, {side} side, reason, lock_time, lock_end_time, active from {pairlock_back_name} """)) diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index 611b084a9..1c219610d 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -1429,7 +1429,7 @@ class PairLock(_DECL_BASE): pair = Column(String(25), nullable=False, index=True) # lock direction - long, short or * (for both) - direction = Column(String(25), nullable=False, default="*") + side = Column(String(25), nullable=False, default="*") reason = Column(String(255), nullable=True) # Time the pair was locked (start time) lock_time = Column(DateTime, nullable=False) @@ -1457,7 +1457,7 @@ class PairLock(_DECL_BASE): if pair: filters.append(PairLock.pair == pair) if side != '*': - filters.append(PairLock.direction == side) + filters.append(PairLock.side == side) return PairLock.query.filter( *filters diff --git a/freqtrade/persistence/pairlock_middleware.py b/freqtrade/persistence/pairlock_middleware.py index b8a092365..ade92355c 100644 --- a/freqtrade/persistence/pairlock_middleware.py +++ b/freqtrade/persistence/pairlock_middleware.py @@ -31,7 +31,7 @@ class PairLocks(): @staticmethod def lock_pair(pair: str, until: datetime, reason: str = None, *, - now: datetime = None, side: str) -> PairLock: + now: datetime = None, side: str = '*') -> PairLock: """ Create PairLock from now to "until". Uses database by default, unless PairLocks.use_db is set to False, @@ -47,7 +47,7 @@ class PairLocks(): lock_time=now or datetime.now(timezone.utc), lock_end_time=timeframe_to_next_date(PairLocks.timeframe, until), reason=reason, - direction=side, + side=side, active=True ) if PairLocks.use_db: @@ -76,7 +76,7 @@ class PairLocks(): lock.lock_end_time >= now and lock.active is True and (pair is None or lock.pair == pair) - and (side == '*' or lock.direction == side) + and (side == '*' or lock.side == side) )] return locks diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 0ae36f0fd..7bb728c66 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -421,7 +421,7 @@ def test_enter_positions_global_pairlock(default_conf_usdt, ticker_usdt, limit_b assert not log_has_re(message, caplog) caplog.clear() - PairLocks.lock_pair('*', arrow.utcnow().shift(minutes=20).datetime, 'Just because') + PairLocks.lock_pair('*', arrow.utcnow().shift(minutes=20).datetime, 'Just because', side='*') n = freqtrade.enter_positions() assert n == 0 assert log_has_re(message, caplog)