Merge pull request #5850 from freqtrade/timeout_forcesell

multiple exit-timeouts can trigger emergencysell
This commit is contained in:
Matthias
2021-11-06 16:20:06 +01:00
committed by GitHub
7 changed files with 39 additions and 5 deletions

View File

@@ -2134,11 +2134,12 @@ def test_check_handle_timedout_buy_exception(default_conf_usdt, ticker_usdt,
def test_check_handle_timedout_sell_usercustom(default_conf_usdt, ticker_usdt, limit_sell_order_old,
mocker, open_trade) -> None:
default_conf_usdt["unfilledtimeout"] = {"buy": 1440, "sell": 1440}
mocker, open_trade, caplog) -> None:
default_conf_usdt["unfilledtimeout"] = {"buy": 1440, "sell": 1440, "exit_timeout_count": 1}
rpc_mock = patch_RPCManager(mocker)
cancel_order_mock = MagicMock()
patch_exchange(mocker)
et_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.execute_trade_exit')
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
fetch_ticker=ticker_usdt,
@@ -2181,6 +2182,14 @@ def test_check_handle_timedout_sell_usercustom(default_conf_usdt, ticker_usdt, l
assert open_trade.is_open is True
assert freqtrade.strategy.check_sell_timeout.call_count == 1
# 2nd canceled trade ...
caplog.clear()
open_trade.open_order_id = 'order_id_2'
mocker.patch('freqtrade.persistence.Trade.get_exit_order_count', return_value=1)
freqtrade.check_handle_timedout()
assert log_has_re('Emergencyselling trade.*', caplog)
assert et_mock.call_count == 1
def test_check_handle_timedout_sell(default_conf_usdt, ticker_usdt, limit_sell_order_old, mocker,
open_trade) -> None:

View File

@@ -13,7 +13,7 @@ from sqlalchemy import create_engine, inspect, text
from freqtrade import constants
from freqtrade.exceptions import DependencyException, OperationalException
from freqtrade.persistence import LocalTrade, Order, Trade, clean_dry_run_db, init_db
from tests.conftest import create_mock_trades, log_has, log_has_re
from tests.conftest import create_mock_trades, create_mock_trades_usdt, log_has, log_has_re
def test_init_create_session(default_conf):
@@ -1190,6 +1190,14 @@ def test_get_best_pair(fee):
assert res[1] == 0.01
@pytest.mark.usefixtures("init_persistence")
def test_get_exit_order_count(fee):
create_mock_trades_usdt(fee)
trade = Trade.get_trades([Trade.pair == 'ETC/USDT']).first()
assert trade.get_exit_order_count() == 1
@pytest.mark.usefixtures("init_persistence")
def test_update_order_from_ccxt(caplog):
# Most basic order return (only has orderid)