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) 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 # let SQLAlchemy create the schema as required
decl_base.metadata.create_all(engine) decl_base.metadata.create_all(engine)
# Copy data back - following the correct schema # Copy data back - following the correct schema
with engine.begin() as connection: with engine.begin() as connection:
connection.execute(text(f"""insert into pairlocks connection.execute(text(f"""insert into pairlocks
(id, pair, direction, reason, lock_time, (id, pair, side, reason, lock_time,
lock_end_time, active) lock_end_time, active)
select id, pair, {direction} direction, reason, lock_time, select id, pair, {side} side, reason, lock_time,
lock_end_time, active lock_end_time, active
from {pairlock_back_name} from {pairlock_back_name}
""")) """))

View File

@ -1429,7 +1429,7 @@ class PairLock(_DECL_BASE):
pair = Column(String(25), nullable=False, index=True) pair = Column(String(25), nullable=False, index=True)
# lock direction - long, short or * (for both) # 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) reason = Column(String(255), nullable=True)
# Time the pair was locked (start time) # Time the pair was locked (start time)
lock_time = Column(DateTime, nullable=False) lock_time = Column(DateTime, nullable=False)
@ -1457,7 +1457,7 @@ class PairLock(_DECL_BASE):
if pair: if pair:
filters.append(PairLock.pair == pair) filters.append(PairLock.pair == pair)
if side != '*': if side != '*':
filters.append(PairLock.direction == side) filters.append(PairLock.side == side)
return PairLock.query.filter( return PairLock.query.filter(
*filters *filters

View File

@ -31,7 +31,7 @@ class PairLocks():
@staticmethod @staticmethod
def lock_pair(pair: str, until: datetime, reason: str = None, *, 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". Create PairLock from now to "until".
Uses database by default, unless PairLocks.use_db is set to False, 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_time=now or datetime.now(timezone.utc),
lock_end_time=timeframe_to_next_date(PairLocks.timeframe, until), lock_end_time=timeframe_to_next_date(PairLocks.timeframe, until),
reason=reason, reason=reason,
direction=side, side=side,
active=True active=True
) )
if PairLocks.use_db: if PairLocks.use_db:
@ -76,7 +76,7 @@ class PairLocks():
lock.lock_end_time >= now lock.lock_end_time >= now
and lock.active is True and lock.active is True
and (pair is None or lock.pair == pair) and (pair is None or lock.pair == pair)
and (side == '*' or lock.direction == side) and (side == '*' or lock.side == side)
)] )]
return locks 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) assert not log_has_re(message, caplog)
caplog.clear() 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() n = freqtrade.enter_positions()
assert n == 0 assert n == 0
assert log_has_re(message, caplog) assert log_has_re(message, caplog)