From 7287e9da1dce45fd839df640e3f918b194e769d6 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 25 Apr 2023 19:34:37 +0200 Subject: [PATCH] Add telegram endpoint for reload_trade --- freqtrade/rpc/telegram.py | 12 ++++++++++++ tests/rpc/test_rpc_telegram.py | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 6e509950c..0779e5795 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -196,6 +196,7 @@ class Telegram(RPCHandler): self._force_enter, order_side=SignalDirection.LONG)), CommandHandler('forceshort', partial( self._force_enter, order_side=SignalDirection.SHORT)), + CommandHandler('reload_trade', self._reload_trade_from_exchange), CommandHandler('trades', self._trades), CommandHandler('delete', self._delete_trade), CommandHandler(['coo', 'cancel_open_order'], self._cancel_open_order), @@ -1074,6 +1075,17 @@ class Telegram(RPCHandler): msg = self._rpc._rpc_stopentry() await self._send_msg(f"Status: `{msg['status']}`") + @authorized_only + async def _reload_trade_from_exchange(self, update: Update, context: CallbackContext) -> None: + """ + Handler for /reload_trade . + """ + if not context.args or len(context.args) == 0: + raise RPCException("Trade-id not set.") + trade_id = context.args[0] + msg = self._rpc._rpc_reload_trade_from_exchange(trade_id) + await self._send_msg(f"Status: `{msg['status']}`") + @authorized_only async def _force_exit(self, update: Update, context: CallbackContext) -> None: """ diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 4b4c2b028..8570b2ad5 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1760,6 +1760,25 @@ async 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]) +async def test_telegram_reload_trade_from_exchange(mocker, update, default_conf, fee, is_short): + + telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) + context = MagicMock() + context.args = [] + + await telegram._reload_trade_from_exchange(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.args = [5] + + await telegram._reload_trade_from_exchange(update=update, context=context) + assert "Status: `Reloaded from orders from exchange`" in msg_mock.call_args_list[0][0][0] + + @pytest.mark.parametrize('is_short', [True, False]) async def test_telegram_delete_open_order(mocker, update, default_conf, fee, is_short, ticker):