Get Longest lock logic
This commit is contained in:
@@ -80,3 +80,35 @@ def test_PairLocks(use_db):
|
||||
assert len(PairLock.query.all()) == 0
|
||||
# Reset use-db variable
|
||||
PairLocks.use_db = True
|
||||
|
||||
|
||||
@pytest.mark.parametrize('use_db', (False, True))
|
||||
@pytest.mark.usefixtures("init_persistence")
|
||||
def test_PairLocks_getlongestlock(use_db):
|
||||
PairLocks.timeframe = '5m'
|
||||
# No lock should be present
|
||||
if use_db:
|
||||
assert len(PairLock.query.all()) == 0
|
||||
else:
|
||||
PairLocks.use_db = False
|
||||
|
||||
assert PairLocks.use_db == use_db
|
||||
|
||||
pair = 'ETH/BTC'
|
||||
assert not PairLocks.is_pair_locked(pair)
|
||||
PairLocks.lock_pair(pair, arrow.utcnow().shift(minutes=4).datetime)
|
||||
# ETH/BTC locked for 4 minutes
|
||||
assert PairLocks.is_pair_locked(pair)
|
||||
lock = PairLocks.get_pair_longest_lock(pair)
|
||||
|
||||
assert lock.lock_end_time.replace(tzinfo=timezone.utc) > arrow.utcnow().shift(minutes=3)
|
||||
assert lock.lock_end_time.replace(tzinfo=timezone.utc) < arrow.utcnow().shift(minutes=14)
|
||||
|
||||
PairLocks.lock_pair(pair, arrow.utcnow().shift(minutes=15).datetime)
|
||||
assert PairLocks.is_pair_locked(pair)
|
||||
|
||||
lock = PairLocks.get_pair_longest_lock(pair)
|
||||
# Must be longer than above
|
||||
assert lock.lock_end_time.replace(tzinfo=timezone.utc) > arrow.utcnow().shift(minutes=14)
|
||||
|
||||
PairLocks.use_db = True
|
||||
|
@@ -692,16 +692,16 @@ def test_enter_positions_global_pairlock(default_conf, ticker, limit_buy_order,
|
||||
freqtrade = FreqtradeBot(default_conf)
|
||||
patch_get_signal(freqtrade)
|
||||
n = freqtrade.enter_positions()
|
||||
message = "Global pairlock active. Not creating new trades."
|
||||
message = r"Global pairlock active until.* Not creating new trades."
|
||||
n = freqtrade.enter_positions()
|
||||
# 0 trades, but it's not because of pairlock.
|
||||
assert n == 0
|
||||
assert not log_has(message, caplog)
|
||||
assert not log_has_re(message, caplog)
|
||||
|
||||
PairLocks.lock_pair('*', arrow.utcnow().shift(minutes=20).datetime, 'Just because')
|
||||
n = freqtrade.enter_positions()
|
||||
assert n == 0
|
||||
assert log_has(message, caplog)
|
||||
assert log_has_re(message, caplog)
|
||||
|
||||
|
||||
def test_create_trade_no_signal(default_conf, fee, mocker) -> None:
|
||||
@@ -3289,7 +3289,7 @@ def test_locked_pairs(default_conf, ticker, fee, ticker_sell_down, mocker, caplo
|
||||
caplog.clear()
|
||||
freqtrade.enter_positions()
|
||||
|
||||
assert log_has(f"Pair {trade.pair} is currently locked.", caplog)
|
||||
assert log_has_re(f"Pair {trade.pair} is still locked.*", caplog)
|
||||
|
||||
|
||||
def test_ignore_roi_if_buy_signal(default_conf, limit_buy_order, limit_buy_order_open,
|
||||
|
Reference in New Issue
Block a user