Merge pull request #8086 from freqtrade/feat/cancel_order
Cancel open orders through UI/telegram
This commit is contained in:
@@ -706,6 +706,46 @@ def test_api_delete_trade(botclient, mocker, fee, markets, is_short):
|
||||
assert_response(rc, 502)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_api_delete_open_order(botclient, mocker, fee, markets, ticker, is_short):
|
||||
ftbot, client = botclient
|
||||
patch_get_signal(ftbot, enter_long=not is_short, enter_short=is_short)
|
||||
stoploss_mock = MagicMock()
|
||||
cancel_mock = MagicMock()
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.exchange.Exchange',
|
||||
markets=PropertyMock(return_value=markets),
|
||||
fetch_ticker=ticker,
|
||||
cancel_order=cancel_mock,
|
||||
cancel_stoploss_order=stoploss_mock,
|
||||
)
|
||||
|
||||
rc = client_delete(client, f"{BASE_URI}/trades/10/open-order")
|
||||
assert_response(rc, 502)
|
||||
assert 'Invalid trade_id.' in rc.json()['error']
|
||||
|
||||
create_mock_trades(fee, is_short=is_short)
|
||||
Trade.commit()
|
||||
|
||||
rc = client_delete(client, f"{BASE_URI}/trades/5/open-order")
|
||||
assert_response(rc, 502)
|
||||
assert 'No open order for trade_id' in rc.json()['error']
|
||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
||||
side_effect=ExchangeError)
|
||||
rc = client_delete(client, f"{BASE_URI}/trades/6/open-order")
|
||||
assert_response(rc, 502)
|
||||
assert 'Order not found.' in rc.json()['error']
|
||||
|
||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
||||
return_value=trade.orders[-1].to_ccxt_object())
|
||||
|
||||
rc = client_delete(client, f"{BASE_URI}/trades/6/open-order")
|
||||
assert_response(rc)
|
||||
assert cancel_mock.call_count == 1
|
||||
|
||||
|
||||
def test_api_logs(botclient):
|
||||
ftbot, client = botclient
|
||||
rc = client_get(client, f"{BASE_URI}/logs")
|
||||
|
@@ -99,7 +99,7 @@ def test_telegram_init(default_conf, mocker, caplog) -> None:
|
||||
message_str = ("rpc.telegram is listening for following commands: [['status'], ['profit'], "
|
||||
"['balance'], ['start'], ['stop'], "
|
||||
"['forcesell', 'forceexit', 'fx'], ['forcebuy', 'forcelong'], ['forceshort'], "
|
||||
"['trades'], ['delete'], ['performance'], "
|
||||
"['trades'], ['delete'], ['coo', 'cancel_open_order'], ['performance'], "
|
||||
"['buys', 'entries'], ['sells', 'exits'], ['mix_tags'], "
|
||||
"['stats'], ['daily'], ['weekly'], ['monthly'], "
|
||||
"['count'], ['locks'], ['unlock', 'delete_locks'], "
|
||||
@@ -1678,6 +1678,40 @@ def test_telegram_delete_trade(mocker, update, default_conf, fee, is_short):
|
||||
assert "Please make sure to take care of this asset" in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
|
||||
@pytest.mark.parametrize('is_short', [True, False])
|
||||
def test_telegram_delete_open_order(mocker, update, default_conf, fee, is_short, ticker):
|
||||
|
||||
mocker.patch.multiple(
|
||||
'freqtrade.exchange.Exchange',
|
||||
fetch_ticker=ticker,
|
||||
)
|
||||
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||
context = MagicMock()
|
||||
context.args = []
|
||||
|
||||
telegram._cancel_open_order(update=update, context=context)
|
||||
assert "Trade-id not set." in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
msg_mock.reset_mock()
|
||||
create_mock_trades(fee, is_short=is_short)
|
||||
|
||||
context = MagicMock()
|
||||
context.args = [5]
|
||||
telegram._cancel_open_order(update=update, context=context)
|
||||
assert "No open order for trade_id" in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
msg_mock.reset_mock()
|
||||
|
||||
trade = Trade.get_trades([Trade.id == 6]).first()
|
||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order',
|
||||
return_value=trade.orders[-1].to_ccxt_object())
|
||||
context = MagicMock()
|
||||
context.args = [6]
|
||||
telegram._cancel_open_order(update=update, context=context)
|
||||
assert msg_mock.call_count == 1
|
||||
assert "Open order canceled." in msg_mock.call_args_list[0][0][0]
|
||||
|
||||
|
||||
def test_help_handle(default_conf, update, mocker) -> None:
|
||||
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||
|
||||
|
@@ -5028,7 +5028,7 @@ def test_startup_update_open_orders(mocker, default_conf_usdt, fee, caplog, is_s
|
||||
assert log_has_re(r"Error updating Order .*", caplog)
|
||||
|
||||
mocker.patch('freqtrade.exchange.Exchange.fetch_order', side_effect=InvalidOrderException)
|
||||
hto_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_timedout_order')
|
||||
hto_mock = mocker.patch('freqtrade.freqtradebot.FreqtradeBot.handle_cancel_order')
|
||||
# Orders which are no longer found after X days should be assumed as canceled.
|
||||
freqtrade.startup_update_open_orders()
|
||||
assert log_has_re(r"Order is older than \d days.*", caplog)
|
||||
|
Reference in New Issue
Block a user