Sort /forcebuy pairs alphabetically, add cancel button

closes #6389
This commit is contained in:
Matthias 2022-02-11 19:37:35 +01:00
parent 6a59103869
commit c9cfc246f1
2 changed files with 12 additions and 7 deletions

View File

@ -914,10 +914,11 @@ class Telegram(RPCHandler):
self._send_msg(str(e)) self._send_msg(str(e))
def _forcebuy_action(self, pair, price=None): def _forcebuy_action(self, pair, price=None):
try: if pair != 'cancel':
self._rpc._rpc_forcebuy(pair, price) try:
except RPCException as e: self._rpc._rpc_forcebuy(pair, price)
self._send_msg(str(e)) except RPCException as e:
self._send_msg(str(e))
def _forcebuy_inline(self, update: Update, _: CallbackContext) -> None: def _forcebuy_inline(self, update: Update, _: CallbackContext) -> None:
if update.callback_query: if update.callback_query:
@ -947,10 +948,13 @@ class Telegram(RPCHandler):
self._forcebuy_action(pair, price) self._forcebuy_action(pair, price)
else: else:
whitelist = self._rpc._rpc_whitelist()['whitelist'] whitelist = self._rpc._rpc_whitelist()['whitelist']
pairs = [InlineKeyboardButton(text=pair, callback_data=pair) for pair in whitelist] pair_buttons = [
InlineKeyboardButton(text=pair, callback_data=pair) for pair in sorted(whitelist)]
buttons_aligned = self._layout_inline_keyboard(pair_buttons)
buttons_aligned.append([InlineKeyboardButton(text='Cancel', callback_data='cancel')])
self._send_msg(msg="Which pair?", self._send_msg(msg="Which pair?",
keyboard=self._layout_inline_keyboard(pairs)) keyboard=buttons_aligned)
@authorized_only @authorized_only
def _trades(self, update: Update, context: CallbackContext) -> None: def _trades(self, update: Update, context: CallbackContext) -> None:

View File

@ -1260,7 +1260,8 @@ def test_forcebuy_no_pair(default_conf, update, mocker) -> None:
assert msg_mock.call_args_list[0][1]['msg'] == 'Which pair?' assert msg_mock.call_args_list[0][1]['msg'] == 'Which pair?'
# assert msg_mock.call_args_list[0][1]['callback_query_handler'] == 'forcebuy' # assert msg_mock.call_args_list[0][1]['callback_query_handler'] == 'forcebuy'
keyboard = msg_mock.call_args_list[0][1]['keyboard'] keyboard = msg_mock.call_args_list[0][1]['keyboard']
assert reduce(lambda acc, x: acc + len(x), keyboard, 0) == 4 # One additional button - cancel
assert reduce(lambda acc, x: acc + len(x), keyboard, 0) == 5
update = MagicMock() update = MagicMock()
update.callback_query = MagicMock() update.callback_query = MagicMock()
update.callback_query.data = 'XRP/USDT' update.callback_query.data = 'XRP/USDT'