realign pairlock naming to side

This commit is contained in:
Matthias 2022-04-24 11:24:15 +02:00
parent fc201bb4ff
commit 845f960a4e
4 changed files with 9 additions and 9 deletions

View File

@ -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}
"""))

View File

@ -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

View File

@ -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

View File

@ -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)