Add test for ask_orderbook validation

This commit is contained in:
Matthias 2021-06-25 20:51:45 +02:00
parent 8c542e4028
commit 59a33d0fa9
5 changed files with 24 additions and 5 deletions

View File

@ -193,7 +193,7 @@ def _validate_ask_orderbook(conf: Dict[str, Any]) -> None:
ask_strategy = conf.get('ask_strategy', {}) ask_strategy = conf.get('ask_strategy', {})
ob_min = ask_strategy.get('order_book_min') ob_min = ask_strategy.get('order_book_min')
ob_max = ask_strategy.get('order_book_max') ob_max = ask_strategy.get('order_book_max')
if ob_min is not None and ob_max is not None: if ob_min is not None and ob_max is not None and ask_strategy.get('use_order_book'):
if ob_min != ob_max: if ob_min != ob_max:
raise OperationalException( raise OperationalException(
"Using order_book_max != order_book_min in ask_strategy is no longer supported." "Using order_book_max != order_book_min in ask_strategy is no longer supported."

View File

@ -1071,8 +1071,8 @@ class Exchange:
rate = order_book[f"{ask_strategy['price_side']}s"][order_book_top - 1][0] rate = order_book[f"{ask_strategy['price_side']}s"][order_book_top - 1][0]
except (IndexError, KeyError) as e: except (IndexError, KeyError) as e:
logger.warning( logger.warning(
"Sell Price at location from orderbook could not be determined." f"Sell Price at location {order_book_top} from orderbook could not be "
f"Orderbook: {order_book}" f"determined. Orderbook: {order_book}"
) )
raise PricingError from e raise PricingError from e
else: else:

View File

@ -1869,7 +1869,8 @@ def test_get_sell_rate_orderbook_exception(default_conf, mocker, caplog):
exchange = get_patched_exchange(mocker, default_conf) exchange = get_patched_exchange(mocker, default_conf)
with pytest.raises(PricingError): with pytest.raises(PricingError):
exchange.get_sell_rate(pair, True) exchange.get_sell_rate(pair, True)
assert log_has_re(r"Sell Price at location 1 from orderbook could not be determined\..*", caplog) assert log_has_re(r"Sell Price at location 1 from orderbook could not be determined\..*",
caplog)
def test_get_sell_rate_exception(default_conf, mocker, caplog): def test_get_sell_rate_exception(default_conf, mocker, caplog):

View File

@ -935,6 +935,23 @@ def test_validate_protections(default_conf, protconf, expected):
validate_config_consistency(conf) validate_config_consistency(conf)
def test_validate_ask_orderbook(default_conf, caplog) -> None:
conf = deepcopy(default_conf)
conf['ask_strategy']['use_order_book'] = True
conf['ask_strategy']['order_book_min'] = 2
conf['ask_strategy']['order_book_max'] = 2
validate_config_consistency(conf)
assert log_has_re(r"DEPRECATED: Please use `order_book_top` instead of.*", caplog)
assert conf['ask_strategy']['order_book_top'] == 2
conf['ask_strategy']['order_book_max'] = 5
with pytest.raises(OperationalException,
match=r"Using order_book_max != order_book_min in ask_strategy.*"):
validate_config_consistency(conf)
def test_load_config_test_comments() -> None: def test_load_config_test_comments() -> None:
""" """
Load config with comments Load config with comments

View File

@ -4026,7 +4026,8 @@ def test_order_book_ask_strategy(default_conf, limit_buy_order_open, limit_buy_o
return_value={'bids': [[]], 'asks': [[]]}) return_value={'bids': [[]], 'asks': [[]]})
with pytest.raises(PricingError): with pytest.raises(PricingError):
freqtrade.handle_trade(trade) freqtrade.handle_trade(trade)
assert log_has_re(r'Sell Price at location 1 from orderbook could not be determined\..*', caplog) assert log_has_re(r'Sell Price at location 1 from orderbook could not be determined\..*',
caplog)
def test_startup_state(default_conf, mocker): def test_startup_state(default_conf, mocker):