From 8a9839fb6dc09cc6966e2ba90645e7dd8982b938 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 4 Apr 2022 19:10:44 +0200 Subject: [PATCH] Update telegram notification settings --- config_examples/config_full.example.json | 2 +- docs/strategy_migration.md | 4 ++++ docs/telegram-usage.md | 4 ++-- freqtrade/constants.py | 2 +- freqtrade/enums/rpcmessagetype.py | 2 +- freqtrade/freqtradebot.py | 2 +- freqtrade/rpc/telegram.py | 6 +++--- freqtrade/rpc/webhook.py | 2 +- tests/rpc/test_rpc_telegram.py | 12 ++++++------ tests/rpc/test_rpc_webhook.py | 2 +- tests/test_freqtradebot.py | 14 +++++++------- 11 files changed, 28 insertions(+), 24 deletions(-) diff --git a/config_examples/config_full.example.json b/config_examples/config_full.example.json index 7f4c83e21..2cec48a27 100644 --- a/config_examples/config_full.example.json +++ b/config_examples/config_full.example.json @@ -141,7 +141,7 @@ "startup": "on", "buy": "on", "buy_fill": "on", - "sell": { + "exit": { "roi": "off", "emergency_exit": "off", "force_exit": "off", diff --git a/docs/strategy_migration.md b/docs/strategy_migration.md index 3f14fc300..7b3378bff 100644 --- a/docs/strategy_migration.md +++ b/docs/strategy_migration.md @@ -51,6 +51,10 @@ You can use the quick summary as checklist. Please refer to the detailed section * `webhooksell` -> `webhookexit` * `webhooksellfill` -> `webhookexitfill` * `webhooksellcancel` -> `webhookexitcancel` + * Telegram notification settings + * `sell` -> `exit` + * `sell_fill` -> `exit_fill` + * `sell_cancel` -> `exit_cancel` diff --git a/docs/telegram-usage.md b/docs/telegram-usage.md index 3ca5cf70b..03f8bcb2b 100644 --- a/docs/telegram-usage.md +++ b/docs/telegram-usage.md @@ -82,7 +82,7 @@ Example configuration showing the different settings: "warning": "on", "startup": "off", "buy": "silent", - "sell": { + "exit": { "roi": "silent", "emergency_exit": "on", "force_exit": "on", @@ -105,7 +105,7 @@ Example configuration showing the different settings: ``` `buy` notifications are sent when the order is placed, while `buy_fill` notifications are sent when the order is filled on the exchange. -`sell` notifications are sent when the order is placed, while `exit_fill` notifications are sent when the order is filled on the exchange. +`exit` notifications are sent when the order is placed, while `exit_fill` notifications are sent when the order is filled on the exchange. `*_fill` notifications are off by default and must be explicitly enabled. `protection_trigger` notifications are sent when a protection triggers and `protection_trigger_global` notifications trigger when global protections are triggered. diff --git a/freqtrade/constants.py b/freqtrade/constants.py index 6c721c416..c36f284b2 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -291,7 +291,7 @@ CONF_SCHEMA = { 'enum': TELEGRAM_SETTING_OPTIONS, 'default': 'off' }, - 'sell': { + 'exit': { 'type': ['string', 'object'], 'additionalProperties': { 'type': 'string', diff --git a/freqtrade/enums/rpcmessagetype.py b/freqtrade/enums/rpcmessagetype.py index 1ef0e29dc..65b636266 100644 --- a/freqtrade/enums/rpcmessagetype.py +++ b/freqtrade/enums/rpcmessagetype.py @@ -14,7 +14,7 @@ class RPCMessageType(Enum): SHORT_FILL = 'short_fill' SHORT_CANCEL = 'short_cancel' - SELL = 'sell' + EXIT = 'exit' EXIT_FILL = 'exit_fill' EXIT_CANCEL = 'exit_cancel' diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index e05b25839..79179143f 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1447,7 +1447,7 @@ class FreqtradeBot(LoggingMixin): msg = { 'type': (RPCMessageType.EXIT_FILL if fill - else RPCMessageType.SELL), + else RPCMessageType.EXIT), 'trade_id': trade.id, 'exchange': trade.exchange.capitalize(), 'pair': trade.pair, diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 5ea92d94e..d854b4212 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -298,7 +298,7 @@ class Telegram(RPCHandler): f"*Amount:* `{msg['amount']:.8f}`\n" f"*Open Rate:* `{msg['open_rate']:.8f}`\n" ) - if msg['type'] == RPCMessageType.SELL: + if msg['type'] == RPCMessageType.EXIT: message += (f"*Current Rate:* `{msg['current_rate']:.8f}`\n" f"*Close Rate:* `{msg['limit']:.8f}`") @@ -312,7 +312,7 @@ class Telegram(RPCHandler): RPCMessageType.SHORT_FILL]: message = self._format_buy_msg(msg) - elif msg_type in [RPCMessageType.SELL, RPCMessageType.EXIT_FILL]: + elif msg_type in [RPCMessageType.EXIT, RPCMessageType.EXIT_FILL]: message = self._format_sell_msg(msg) elif msg_type in (RPCMessageType.BUY_CANCEL, RPCMessageType.SHORT_CANCEL, @@ -355,7 +355,7 @@ class Telegram(RPCHandler): msg_type = msg['type'] noti = '' - if msg_type == RPCMessageType.SELL: + if msg_type == RPCMessageType.EXIT: sell_noti = self._config['telegram'] \ .get('notification_settings', {}).get(str(msg_type), {}) # For backward compatibility sell still can be string diff --git a/freqtrade/rpc/webhook.py b/freqtrade/rpc/webhook.py index 9d2fb880d..e9ea9f3ac 100644 --- a/freqtrade/rpc/webhook.py +++ b/freqtrade/rpc/webhook.py @@ -51,7 +51,7 @@ class Webhook(RPCHandler): valuedict = whconfig.get('webhookbuycancel', None) elif msg['type'] in [RPCMessageType.BUY_FILL, RPCMessageType.SHORT_FILL]: valuedict = whconfig.get('webhookbuyfill', None) - elif msg['type'] == RPCMessageType.SELL: + elif msg['type'] == RPCMessageType.EXIT: valuedict = whconfig.get('webhookexit', whconfig.get('webhooksell', None)) elif msg['type'] == RPCMessageType.EXIT_FILL: valuedict = whconfig.get('webhookexitfill', whconfig.get('webhookexitfill', None)) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 9961a3357..801a27684 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1040,7 +1040,7 @@ def test_telegram_forcesell_handle(default_conf, update, ticker, fee, assert msg_mock.call_count == 4 last_msg = msg_mock.call_args_list[-2][0][0] assert { - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'ETH/BTC', @@ -1109,7 +1109,7 @@ def test_telegram_forcesell_down_handle(default_conf, update, ticker, fee, last_msg = msg_mock.call_args_list[-2][0][0] assert { - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'ETH/BTC', @@ -1168,7 +1168,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, mocker) -> None assert msg_mock.call_count == 8 msg = msg_mock.call_args_list[0][0][0] assert { - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'ETH/BTC', @@ -1918,7 +1918,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None: old_convamount = telegram._rpc._fiat_converter.convert_amount telegram._rpc._fiat_converter.convert_amount = lambda a, b, c: -24.812 telegram.send_msg({ - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'KEY/ETH', @@ -1954,7 +1954,7 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None: msg_mock.reset_mock() telegram.send_msg({ - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'KEY/ETH', @@ -2155,7 +2155,7 @@ def test_send_msg_sell_notification_no_fiat( telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) telegram.send_msg({ - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'KEY/ETH', diff --git a/tests/rpc/test_rpc_webhook.py b/tests/rpc/test_rpc_webhook.py index b4c1caac3..cf2d1bf98 100644 --- a/tests/rpc/test_rpc_webhook.py +++ b/tests/rpc/test_rpc_webhook.py @@ -232,7 +232,7 @@ def test_send_msg_webhook(default_conf, mocker): msg_mock.reset_mock() msg = { - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'exchange': 'Binance', 'pair': 'ETH/BTC', 'gain': "profit", diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index 53801335d..f176783ef 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -3091,7 +3091,7 @@ def test_execute_trade_exit_up(default_conf_usdt, ticker_usdt, fee, ticker_usdt_ last_msg = rpc_mock.call_args_list[-1][0][0] assert { 'trade_id': 1, - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'exchange': 'Binance', 'pair': 'ETH/USDT', 'gain': 'profit', @@ -3150,7 +3150,7 @@ def test_execute_trade_exit_down(default_conf_usdt, ticker_usdt, fee, ticker_usd assert rpc_mock.call_count == 2 last_msg = rpc_mock.call_args_list[-1][0][0] assert { - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'ETH/USDT', @@ -3232,7 +3232,7 @@ def test_execute_trade_exit_custom_exit_price( last_msg = rpc_mock.call_args_list[-1][0][0] assert { 'trade_id': 1, - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'exchange': 'Binance', 'pair': 'ETH/USDT', 'direction': 'Short' if trade.is_short else 'Long', @@ -3299,7 +3299,7 @@ def test_execute_trade_exit_down_stoploss_on_exchange_dry_run( last_msg = rpc_mock.call_args_list[-1][0][0] assert { - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'ETH/USDT', @@ -3490,12 +3490,12 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit( if is_short: assert rpc_mock.call_args_list[0][0][0]['type'] == RPCMessageType.SHORT assert rpc_mock.call_args_list[1][0][0]['type'] == RPCMessageType.SHORT_FILL - assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.SELL + assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.EXIT else: assert rpc_mock.call_args_list[0][0][0]['type'] == RPCMessageType.BUY assert rpc_mock.call_args_list[1][0][0]['type'] == RPCMessageType.BUY_FILL - assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.SELL + assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.EXIT @pytest.mark.parametrize( @@ -3563,7 +3563,7 @@ def test_execute_trade_exit_market_order( assert rpc_mock.call_count == 3 last_msg = rpc_mock.call_args_list[-2][0][0] assert { - 'type': RPCMessageType.SELL, + 'type': RPCMessageType.EXIT, 'trade_id': 1, 'exchange': 'Binance', 'pair': 'ETH/USDT',