update pairlock tests
This commit is contained in:
parent
845f960a4e
commit
4942d73693
@ -7,7 +7,7 @@ from decimal import Decimal
|
|||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from sqlalchemy import (Boolean, Column, DateTime, Enum, Float, ForeignKey, Integer, String,
|
from sqlalchemy import (Boolean, Column, DateTime, Enum, Float, ForeignKey, Integer, String,
|
||||||
create_engine, desc, func, inspect)
|
create_engine, desc, func, inspect, or_)
|
||||||
from sqlalchemy.exc import NoSuchModuleError
|
from sqlalchemy.exc import NoSuchModuleError
|
||||||
from sqlalchemy.orm import Query, declarative_base, relationship, scoped_session, sessionmaker
|
from sqlalchemy.orm import Query, declarative_base, relationship, scoped_session, sessionmaker
|
||||||
from sqlalchemy.pool import StaticPool
|
from sqlalchemy.pool import StaticPool
|
||||||
@ -1441,7 +1441,8 @@ class PairLock(_DECL_BASE):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
lock_time = self.lock_time.strftime(DATETIME_PRINT_FORMAT)
|
lock_time = self.lock_time.strftime(DATETIME_PRINT_FORMAT)
|
||||||
lock_end_time = self.lock_end_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}, '
|
return (
|
||||||
|
f'PairLock(id={self.id}, pair={self.pair}, side={self.side}, lock_time={lock_time}, '
|
||||||
f'lock_end_time={lock_end_time}, reason={self.reason}, active={self.active})')
|
f'lock_end_time={lock_end_time}, reason={self.reason}, active={self.active})')
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -1457,7 +1458,9 @@ 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.side == side)
|
filters.append(or_(PairLock.side == side, PairLock.side == '*'))
|
||||||
|
else:
|
||||||
|
filters.append(PairLock.side == '*')
|
||||||
|
|
||||||
return PairLock.query.filter(
|
return PairLock.query.filter(
|
||||||
*filters
|
*filters
|
||||||
|
@ -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.side == side)
|
and (lock.side == '*' or lock.side == side)
|
||||||
)]
|
)]
|
||||||
return locks
|
return locks
|
||||||
|
|
||||||
|
@ -21,8 +21,22 @@ def test_PairLocks(use_db):
|
|||||||
pair = 'ETH/BTC'
|
pair = 'ETH/BTC'
|
||||||
assert not PairLocks.is_pair_locked(pair)
|
assert not PairLocks.is_pair_locked(pair)
|
||||||
PairLocks.lock_pair(pair, arrow.utcnow().shift(minutes=4).datetime)
|
PairLocks.lock_pair(pair, arrow.utcnow().shift(minutes=4).datetime)
|
||||||
# ETH/BTC locked for 4 minutes
|
# ETH/BTC locked for 4 minutes (on both sides)
|
||||||
assert PairLocks.is_pair_locked(pair)
|
assert PairLocks.is_pair_locked(pair)
|
||||||
|
assert PairLocks.is_pair_locked(pair, side='long')
|
||||||
|
assert PairLocks.is_pair_locked(pair, side='short')
|
||||||
|
|
||||||
|
pair = 'BNB/BTC'
|
||||||
|
PairLocks.lock_pair(pair, arrow.utcnow().shift(minutes=4).datetime, side='long')
|
||||||
|
assert not PairLocks.is_pair_locked(pair)
|
||||||
|
assert PairLocks.is_pair_locked(pair, side='long')
|
||||||
|
assert not PairLocks.is_pair_locked(pair, side='short')
|
||||||
|
|
||||||
|
pair = 'BNB/USDT'
|
||||||
|
PairLocks.lock_pair(pair, arrow.utcnow().shift(minutes=4).datetime, side='short')
|
||||||
|
assert not PairLocks.is_pair_locked(pair)
|
||||||
|
assert not PairLocks.is_pair_locked(pair, side='long')
|
||||||
|
assert PairLocks.is_pair_locked(pair, side='short')
|
||||||
|
|
||||||
# XRP/BTC should not be locked now
|
# XRP/BTC should not be locked now
|
||||||
pair = 'XRP/BTC'
|
pair = 'XRP/BTC'
|
||||||
|
Loading…
Reference in New Issue
Block a user