Add tests for max_adjustment_buy handling

This commit is contained in:
Matthias 2022-01-23 19:07:37 +01:00
parent 7429f535c1
commit 57067ce88d
2 changed files with 31 additions and 2 deletions

View File

@ -464,8 +464,8 @@ class FreqtradeBot(LoggingMixin):
try:
self.check_and_call_adjust_trade_position(trade)
except DependencyException as exception:
logger.warning('Unable to adjust position of trade for %s: %s',
trade.pair, exception)
logger.warning(
f"Unable to adjust position of trade for {trade.pair}: {exception}")
def check_and_call_adjust_trade_position(self, trade: Trade):
"""

View File

@ -4550,3 +4550,32 @@ def test_position_adjust(mocker, default_conf_usdt, fee) -> None:
# Make sure the closed order is found as the second order.
order = trade.select_order('buy', False)
assert order.order_id == '652'
def test_process_open_trade_positions_exception(mocker, default_conf_usdt, fee, caplog) -> None:
default_conf_usdt.update({
"position_adjustment_enable": True,
})
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.check_and_call_adjust_trade_position',
side_effect=DependencyException())
create_mock_trades(fee)
freqtrade.process_open_trade_positions()
assert log_has_re(r"Unable to adjust position of trade for .*", caplog)
def test_check_and_call_adjust_trade_position(mocker, default_conf_usdt, fee, caplog) -> None:
default_conf_usdt.update({
"position_adjustment_enable": True,
"max_buy_position_adjustment": 0,
})
freqtrade = get_patched_freqtradebot(mocker, default_conf_usdt)
create_mock_trades(fee)
caplog.set_level(logging.DEBUG)
freqtrade.process_open_trade_positions()
assert log_has_re(r"Max adjustment buy for .* has been reached\.", caplog)