From c0d60c63ab0a5f8e9dd72db8b7eb9c5ff6654bbb Mon Sep 17 00:00:00 2001 From: ecoppen <51025241+ecoppen@users.noreply.github.com> Date: Wed, 10 Aug 2022 14:56:38 +0100 Subject: [PATCH 1/6] Optional /whitelist args - sorted, nobase Added two optional arguments for whitelist - `sorted` for alphabetical order and `nobase` for displaying the whitelist without base currency e.g. /USDT. Updated help with optional commands. Added a space in an unrelated help message. --- freqtrade/rpc/telegram.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 9e0cd7d86..c3b41a907 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -1368,6 +1368,12 @@ class Telegram(RPCHandler): try: whitelist = self._rpc._rpc_whitelist() + if context.args: + if "sorted" in context.args: + whitelist['whitelist'] = sorted(whitelist['whitelist']) + if "nobase" in context.args: + whitelist['whitelist'] = [pair.split("/")[0] for pair in whitelist['whitelist']] + message = f"Using whitelist `{whitelist['method']}` with {whitelist['length']} pairs\n" message += f"`{', '.join(whitelist['whitelist'])}`" @@ -1487,7 +1493,8 @@ class Telegram(RPCHandler): "*/fx |all:* `Alias to /forceexit`\n" f"{force_enter_text if self._config.get('force_entry_enable', False) else ''}" "*/delete :* `Instantly delete the given trade in the database`\n" - "*/whitelist:* `Show current whitelist` \n" + "*/whitelist [sorted] [nobase]:* `Show current whitelist. Optionally in " + "order and/or without the base currency.`\n" "*/blacklist [pair]:* `Show current blacklist, or adds one or more pairs " "to the blacklist.` \n" "*/blacklist_delete [pairs]| /bl_delete [pairs]:* " @@ -1524,7 +1531,7 @@ class Telegram(RPCHandler): "*/weekly :* `Shows statistics per week, over the last n weeks`\n" "*/monthly :* `Shows statistics per month, over the last n months`\n" "*/stats:* `Shows Wins / losses by Sell reason as well as " - "Avg. holding durationsfor buys and sells.`\n" + "Avg. holding durations for buys and sells.`\n" "*/help:* `This help message`\n" "*/version:* `Show version`" ) From ace96264837b1be868458239fa3143db66d01767 Mon Sep 17 00:00:00 2001 From: ecoppen <51025241+ecoppen@users.noreply.github.com> Date: Wed, 10 Aug 2022 15:04:24 +0100 Subject: [PATCH 2/6] Update tests for sorted and nobase Tests for PR #7211 --- tests/rpc/test_rpc_telegram.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 2c9528b5e..8049a10e9 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1458,6 +1458,23 @@ def test_whitelist_static(default_conf, update, mocker) -> None: assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH/BTC, LTC/BTC, XRP/BTC, NEO/BTC`" in msg_mock.call_args_list[0][0][0]) + context = MagicMock() + context.args = ['sorted'] + msg_mock.reset_mock() + assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" + "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in sorted(msg_mock.call_args_list[0][0][0])) + + context = MagicMock() + context.args = ['nobase'] + msg_mock.reset_mock() + assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" + "`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0]) + + context = MagicMock() + context.args = ['nobase', 'sorted'] + msg_mock.reset_mock() + assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" + "`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0]) def test_whitelist_dynamic(default_conf, update, mocker) -> None: mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True)) @@ -1471,6 +1488,23 @@ def test_whitelist_dynamic(default_conf, update, mocker) -> None: assert ("Using whitelist `['VolumePairList']` with 4 pairs\n" "`ETH/BTC, LTC/BTC, XRP/BTC, NEO/BTC`" in msg_mock.call_args_list[0][0][0]) + context = MagicMock() + context.args = ['sorted'] + msg_mock.reset_mock() + assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" + "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in sorted(msg_mock.call_args_list[0][0][0])) + + context = MagicMock() + context.args = ['nobase'] + msg_mock.reset_mock() + assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" + "`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0]) + + context = MagicMock() + context.args = ['nobase', 'sorted'] + msg_mock.reset_mock() + assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" + "`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0]) def test_blacklist_static(default_conf, update, mocker) -> None: From 923f73a5161dd861be3ae2885856a0b0ac54b640 Mon Sep 17 00:00:00 2001 From: ecoppen <51025241+ecoppen@users.noreply.github.com> Date: Fri, 12 Aug 2022 19:56:46 +0100 Subject: [PATCH 3/6] nobase -> baseonly --- freqtrade/rpc/telegram.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index c3b41a907..88222608e 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -1371,7 +1371,7 @@ class Telegram(RPCHandler): if context.args: if "sorted" in context.args: whitelist['whitelist'] = sorted(whitelist['whitelist']) - if "nobase" in context.args: + if "baseonly" in context.args: whitelist['whitelist'] = [pair.split("/")[0] for pair in whitelist['whitelist']] message = f"Using whitelist `{whitelist['method']}` with {whitelist['length']} pairs\n" @@ -1493,8 +1493,8 @@ class Telegram(RPCHandler): "*/fx |all:* `Alias to /forceexit`\n" f"{force_enter_text if self._config.get('force_entry_enable', False) else ''}" "*/delete :* `Instantly delete the given trade in the database`\n" - "*/whitelist [sorted] [nobase]:* `Show current whitelist. Optionally in " - "order and/or without the base currency.`\n" + "*/whitelist [sorted] [baseonly]:* `Show current whitelist. Optionally in " + "order and/or only displaying the base currency of each pairing.`\n" "*/blacklist [pair]:* `Show current blacklist, or adds one or more pairs " "to the blacklist.` \n" "*/blacklist_delete [pairs]| /bl_delete [pairs]:* " From ccc0ad6f642aa875c06bc39bb34a646c07cddb10 Mon Sep 17 00:00:00 2001 From: ecoppen <51025241+ecoppen@users.noreply.github.com> Date: Fri, 12 Aug 2022 19:58:41 +0100 Subject: [PATCH 4/6] fix - reload whitelist Should fix the issue, if not I'll move development to a different computer and get local testing running properly. --- tests/rpc/test_rpc_telegram.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 8049a10e9..cd26e744f 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1461,21 +1461,25 @@ def test_whitelist_static(default_conf, update, mocker) -> None: context = MagicMock() context.args = ['sorted'] msg_mock.reset_mock() + telegram._whitelist(update=update, context=MagicMock()) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in sorted(msg_mock.call_args_list[0][0][0])) context = MagicMock() - context.args = ['nobase'] + context.args = ['baseonly'] msg_mock.reset_mock() + telegram._whitelist(update=update, context=MagicMock()) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0]) context = MagicMock() - context.args = ['nobase', 'sorted'] + context.args = ['baseonly', 'sorted'] msg_mock.reset_mock() + telegram._whitelist(update=update, context=MagicMock()) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0]) + def test_whitelist_dynamic(default_conf, update, mocker) -> None: mocker.patch('freqtrade.exchange.Exchange.exchange_has', MagicMock(return_value=True)) default_conf['pairlists'] = [{'method': 'VolumePairList', @@ -1491,21 +1495,25 @@ def test_whitelist_dynamic(default_conf, update, mocker) -> None: context = MagicMock() context.args = ['sorted'] msg_mock.reset_mock() + telegram._whitelist(update=update, context=MagicMock()) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in sorted(msg_mock.call_args_list[0][0][0])) context = MagicMock() - context.args = ['nobase'] + context.args = ['baseonly'] msg_mock.reset_mock() + telegram._whitelist(update=update, context=MagicMock()) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0]) context = MagicMock() - context.args = ['nobase', 'sorted'] + context.args = ['baseonly', 'sorted'] msg_mock.reset_mock() + telegram._whitelist(update=update, context=MagicMock()) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0]) + def test_blacklist_static(default_conf, update, mocker) -> None: telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) From 2312b86a66bbe31a1aa28e52e82b74db77bbdbbc Mon Sep 17 00:00:00 2001 From: ecoppen <51025241+ecoppen@users.noreply.github.com> Date: Fri, 12 Aug 2022 19:59:08 +0100 Subject: [PATCH 5/6] Update telegram-usage.md Add the optional arguments to the documentation. --- docs/telegram-usage.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/telegram-usage.md b/docs/telegram-usage.md index a690e18b9..add889681 100644 --- a/docs/telegram-usage.md +++ b/docs/telegram-usage.md @@ -187,7 +187,7 @@ official commands. You can ask at any moment for help with `/help`. | `/stats` | Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells | `/exits` | Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells | `/entries` | Shows Wins / losses by Exit reason as well as Avg. holding durations for buys and sells -| `/whitelist` | Show the current whitelist +| `/whitelist [sorted] [baseonly]` | Show the current whitelist. Optionally display in alphabetical order and/or with just the base currency of each pairing. | `/blacklist [pair]` | Show the current blacklist, or adds a pair to the blacklist. | `/edge` | Show validated pairs by Edge if it is enabled. | `/help` | Show help message From 61acbf21d0372a87401884fdbfa03c8a16a6264e Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 13 Aug 2022 15:46:06 +0200 Subject: [PATCH 6/6] Fix broken telegram tests --- tests/rpc/test_rpc_telegram.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index cd26e744f..a30115bd9 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1461,21 +1461,21 @@ def test_whitelist_static(default_conf, update, mocker) -> None: context = MagicMock() context.args = ['sorted'] msg_mock.reset_mock() - telegram._whitelist(update=update, context=MagicMock()) + telegram._whitelist(update=update, context=context) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" - "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in sorted(msg_mock.call_args_list[0][0][0])) + "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in msg_mock.call_args_list[0][0][0]) context = MagicMock() context.args = ['baseonly'] msg_mock.reset_mock() - telegram._whitelist(update=update, context=MagicMock()) + telegram._whitelist(update=update, context=context) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0]) context = MagicMock() context.args = ['baseonly', 'sorted'] msg_mock.reset_mock() - telegram._whitelist(update=update, context=MagicMock()) + telegram._whitelist(update=update, context=context) assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" "`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0]) @@ -1495,22 +1495,22 @@ def test_whitelist_dynamic(default_conf, update, mocker) -> None: context = MagicMock() context.args = ['sorted'] msg_mock.reset_mock() - telegram._whitelist(update=update, context=MagicMock()) - assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" - "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in sorted(msg_mock.call_args_list[0][0][0])) + telegram._whitelist(update=update, context=context) + assert ("Using whitelist `['VolumePairList']` with 4 pairs\n" + "`ETH/BTC, LTC/BTC, NEO/BTC, XRP/BTC`" in msg_mock.call_args_list[0][0][0]) context = MagicMock() context.args = ['baseonly'] msg_mock.reset_mock() - telegram._whitelist(update=update, context=MagicMock()) - assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" + telegram._whitelist(update=update, context=context) + assert ("Using whitelist `['VolumePairList']` with 4 pairs\n" "`ETH, LTC, XRP, NEO`" in msg_mock.call_args_list[0][0][0]) context = MagicMock() context.args = ['baseonly', 'sorted'] msg_mock.reset_mock() - telegram._whitelist(update=update, context=MagicMock()) - assert ("Using whitelist `['StaticPairList']` with 4 pairs\n" + telegram._whitelist(update=update, context=context) + assert ("Using whitelist `['VolumePairList']` with 4 pairs\n" "`ETH, LTC, NEO, XRP`" in msg_mock.call_args_list[0][0][0])