Add telegram endpoint for reload_trade

This commit is contained in:
Matthias 2023-04-25 19:34:37 +02:00
parent 0c22710ddd
commit 7287e9da1d
2 changed files with 31 additions and 0 deletions

View File

@ -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 <tradeid>.
"""
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:
"""

View File

@ -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):