From eff636ba53b3556d816e459b18e657b762f9ada3 Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 4 Apr 2022 19:29:15 +0200 Subject: [PATCH] Update RPC message types to ENTRY --- config_examples/config_full.example.json | 6 ++-- docs/strategy_migration.md | 3 ++ docs/telegram-usage.md | 8 +++--- .../configuration/deprecated_settings.py | 6 ++++ freqtrade/constants.py | 12 ++++---- freqtrade/enums/rpcmessagetype.py | 10 ++----- freqtrade/freqtradebot.py | 9 ++---- freqtrade/rpc/telegram.py | 17 +++++------ freqtrade/rpc/webhook.py | 6 ++-- tests/rpc/test_rpc_telegram.py | 28 +++++++++---------- tests/rpc/test_rpc_webhook.py | 18 ++++++------ tests/test_freqtradebot.py | 12 ++------ 12 files changed, 64 insertions(+), 71 deletions(-) diff --git a/config_examples/config_full.example.json b/config_examples/config_full.example.json index 2cec48a27..33a267612 100644 --- a/config_examples/config_full.example.json +++ b/config_examples/config_full.example.json @@ -139,8 +139,8 @@ "status": "on", "warning": "on", "startup": "on", - "buy": "on", - "buy_fill": "on", + "entry": "on", + "entry_fill": "on", "exit": { "roi": "off", "emergency_exit": "off", @@ -152,7 +152,7 @@ "custom_exit": "off" }, "exit_fill": "on", - "buy_cancel": "on", + "entry_cancel": "on", "exit_cancel": "on", "protection_trigger": "off", "protection_trigger_global": "on" diff --git a/docs/strategy_migration.md b/docs/strategy_migration.md index 7b3378bff..be93f9040 100644 --- a/docs/strategy_migration.md +++ b/docs/strategy_migration.md @@ -52,6 +52,9 @@ You can use the quick summary as checklist. Please refer to the detailed section * `webhooksellfill` -> `webhookexitfill` * `webhooksellcancel` -> `webhookexitcancel` * Telegram notification settings + * `buy` -> `entry` + * `buy_fill` -> `entry_fill` + * `buy_cancel` -> `entry_cancel` * `sell` -> `exit` * `sell_fill` -> `exit_fill` * `sell_cancel` -> `exit_cancel` diff --git a/docs/telegram-usage.md b/docs/telegram-usage.md index 03f8bcb2b..29187cf95 100644 --- a/docs/telegram-usage.md +++ b/docs/telegram-usage.md @@ -81,7 +81,7 @@ Example configuration showing the different settings: "status": "silent", "warning": "on", "startup": "off", - "buy": "silent", + "entry": "silent", "exit": { "roi": "silent", "emergency_exit": "on", @@ -92,9 +92,9 @@ Example configuration showing the different settings: "stoploss_on_exchange": "on", "custom_exit": "silent" }, - "buy_cancel": "silent", + "entry_cancel": "silent", "exit_cancel": "on", - "buy_fill": "off", + "entry_fill": "off", "exit_fill": "off", "protection_trigger": "off", "protection_trigger_global": "on" @@ -104,7 +104,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. +`entry` notifications are sent when the order is placed, while `entry_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/configuration/deprecated_settings.py b/freqtrade/configuration/deprecated_settings.py index 06d75688d..18b51ffac 100644 --- a/freqtrade/configuration/deprecated_settings.py +++ b/freqtrade/configuration/deprecated_settings.py @@ -90,6 +90,12 @@ def process_temporary_deprecated_settings(config: Dict[str, Any]) -> None: 'notification_settings', 'exit_fill') process_deprecated_setting(config['telegram'], 'notification_settings', 'sell_cancel', 'notification_settings', 'exit_cancel') + process_deprecated_setting(config['telegram'], 'notification_settings', 'buy', + 'notification_settings', 'entry') + process_deprecated_setting(config['telegram'], 'notification_settings', 'buy_fill', + 'notification_settings', 'entry_fill') + process_deprecated_setting(config['telegram'], 'notification_settings', 'buy_cancel', + 'notification_settings', 'entry_cancel') if config.get('webhook'): process_deprecated_setting(config, 'webhook', 'webhooksell', 'webhook', 'webhookexit') process_deprecated_setting(config, 'webhook', 'webhooksellcancel', diff --git a/freqtrade/constants.py b/freqtrade/constants.py index c36f284b2..b99f017d5 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -285,12 +285,12 @@ CONF_SCHEMA = { 'status': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS}, 'warning': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS}, 'startup': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS}, - 'buy': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS}, - 'buy_cancel': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS}, - 'buy_fill': {'type': 'string', - 'enum': TELEGRAM_SETTING_OPTIONS, - 'default': 'off' - }, + 'entry': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS}, + 'entry_cancel': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS}, + 'entry_fill': {'type': 'string', + 'enum': TELEGRAM_SETTING_OPTIONS, + 'default': 'off' + }, 'exit': { 'type': ['string', 'object'], 'additionalProperties': { diff --git a/freqtrade/enums/rpcmessagetype.py b/freqtrade/enums/rpcmessagetype.py index 65b636266..584a011c2 100644 --- a/freqtrade/enums/rpcmessagetype.py +++ b/freqtrade/enums/rpcmessagetype.py @@ -6,13 +6,9 @@ class RPCMessageType(Enum): WARNING = 'warning' STARTUP = 'startup' - BUY = 'buy' - BUY_FILL = 'buy_fill' - BUY_CANCEL = 'buy_cancel' - - SHORT = 'short' - SHORT_FILL = 'short_fill' - SHORT_CANCEL = 'short_cancel' + ENTRY = 'entry' + ENTRY_FILL = 'entry_fill' + ENTRY_CANCEL = 'entry_cancel' EXIT = 'exit' EXIT_FILL = 'exit_fill' diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 79179143f..ccdfbefb4 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -819,10 +819,7 @@ class FreqtradeBot(LoggingMixin): """ Sends rpc notification when a entry order occurred. """ - if fill: - msg_type = RPCMessageType.SHORT_FILL if trade.is_short else RPCMessageType.BUY_FILL - else: - msg_type = RPCMessageType.SHORT if trade.is_short else RPCMessageType.BUY + msg_type = RPCMessageType.ENTRY_FILL if fill else RPCMessageType.ENTRY open_rate = safe_value_fallback(order, 'average', 'price') if open_rate is None: open_rate = trade.open_rate @@ -861,10 +858,10 @@ class FreqtradeBot(LoggingMixin): """ current_rate = self.exchange.get_rate( trade.pair, side='entry', is_short=trade.is_short, refresh=False) - msg_type = RPCMessageType.SHORT_CANCEL if trade.is_short else RPCMessageType.BUY_CANCEL + msg = { 'trade_id': trade.id, - 'type': msg_type, + 'type': RPCMessageType.ENTRY_CANCEL, 'buy_tag': trade.enter_tag, 'enter_tag': trade.enter_tag, 'exchange': self.exchange.name.capitalize(), diff --git a/freqtrade/rpc/telegram.py b/freqtrade/rpc/telegram.py index 829807c97..34774fb59 100644 --- a/freqtrade/rpc/telegram.py +++ b/freqtrade/rpc/telegram.py @@ -230,11 +230,11 @@ class Telegram(RPCHandler): msg['stake_amount'], msg['stake_currency'], msg['fiat_currency']) else: msg['stake_amount_fiat'] = 0 - is_fill = msg['type'] in [RPCMessageType.BUY_FILL, RPCMessageType.SHORT_FILL] + is_fill = msg['type'] in [RPCMessageType.ENTRY_FILL] emoji = '\N{CHECK MARK}' if is_fill else '\N{LARGE BLUE CIRCLE}' enter_side = ({'enter': 'Long', 'entered': 'Longed'} if msg['type'] - in [RPCMessageType.BUY_FILL, RPCMessageType.BUY] + in [RPCMessageType.ENTRY_FILL, RPCMessageType.ENTRY] else {'enter': 'Short', 'entered': 'Shorted'}) message = ( f"{emoji} *{msg['exchange']}:*" @@ -246,9 +246,9 @@ class Telegram(RPCHandler): if msg.get('leverage') and msg.get('leverage', 1.0) != 1.0: message += f"*Leverage:* `{msg['leverage']}`\n" - if msg['type'] in [RPCMessageType.BUY_FILL, RPCMessageType.SHORT_FILL]: + if msg['type'] in [RPCMessageType.ENTRY_FILL]: message += f"*Open Rate:* `{msg['open_rate']:.8f}`\n" - elif msg['type'] in [RPCMessageType.BUY, RPCMessageType.SHORT]: + elif msg['type'] in [RPCMessageType.ENTRY]: message += f"*Open Rate:* `{msg['limit']:.8f}`\n"\ f"*Current Rate:* `{msg['current_rate']:.8f}`\n" @@ -308,17 +308,14 @@ class Telegram(RPCHandler): return message def compose_message(self, msg: Dict[str, Any], msg_type: RPCMessageType) -> str: - if msg_type in [RPCMessageType.BUY, RPCMessageType.BUY_FILL, RPCMessageType.SHORT, - RPCMessageType.SHORT_FILL]: + if msg_type in [RPCMessageType.ENTRY, RPCMessageType.ENTRY_FILL]: message = self._format_entry_msg(msg) elif msg_type in [RPCMessageType.EXIT, RPCMessageType.EXIT_FILL]: message = self._format_exit_msg(msg) - elif msg_type in (RPCMessageType.BUY_CANCEL, RPCMessageType.SHORT_CANCEL, - RPCMessageType.EXIT_CANCEL): - msg['message_side'] = 'enter' if msg_type in [RPCMessageType.BUY_CANCEL, - RPCMessageType.SHORT_CANCEL] else 'exit' + elif msg_type in (RPCMessageType.ENTRY_CANCEL, RPCMessageType.EXIT_CANCEL): + msg['message_side'] = 'enter' if msg_type in [RPCMessageType.ENTRY_CANCEL] else 'exit' message = ("\N{WARNING SIGN} *{exchange}:* " "Cancelling {message_side} Order for {pair} (#{trade_id}). " "Reason: {reason}.".format(**msg)) diff --git a/freqtrade/rpc/webhook.py b/freqtrade/rpc/webhook.py index dbb87f1fe..a42929cc4 100644 --- a/freqtrade/rpc/webhook.py +++ b/freqtrade/rpc/webhook.py @@ -44,11 +44,11 @@ class Webhook(RPCHandler): """ Send a message to telegram channel """ try: whconfig = self._config['webhook'] - if msg['type'] in [RPCMessageType.BUY, RPCMessageType.SHORT]: + if msg['type'] in [RPCMessageType.ENTRY]: valuedict = whconfig.get('webhookbuy', None) - elif msg['type'] in [RPCMessageType.BUY_CANCEL, RPCMessageType.SHORT_CANCEL]: + elif msg['type'] in [RPCMessageType.ENTRY_CANCEL]: valuedict = whconfig.get('webhookbuycancel', None) - elif msg['type'] in [RPCMessageType.BUY_FILL, RPCMessageType.SHORT_FILL]: + elif msg['type'] in [RPCMessageType.ENTRY_FILL]: valuedict = whconfig.get('webhookbuyfill', None) elif msg['type'] == RPCMessageType.EXIT: valuedict = whconfig.get('webhookexit', None) diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 801a27684..ab7d051f4 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1771,10 +1771,10 @@ def test_show_config_handle(default_conf, update, mocker) -> None: @pytest.mark.parametrize('message_type,enter,enter_signal,leverage', [ - (RPCMessageType.BUY, 'Long', 'long_signal_01', None), - (RPCMessageType.BUY, 'Long', 'long_signal_01', 1.0), - (RPCMessageType.BUY, 'Long', 'long_signal_01', 5.0), - (RPCMessageType.SHORT, 'Short', 'short_signal_01', 2.0)]) + (RPCMessageType.ENTRY, 'Long', 'long_signal_01', None), + (RPCMessageType.ENTRY, 'Long', 'long_signal_01', 1.0), + (RPCMessageType.ENTRY, 'Long', 'long_signal_01', 5.0), + (RPCMessageType.ENTRY, 'Short', 'short_signal_01', 2.0)]) def test_send_msg_buy_notification(default_conf, mocker, caplog, message_type, enter, enter_signal, leverage) -> None: @@ -1827,8 +1827,8 @@ def test_send_msg_buy_notification(default_conf, mocker, caplog, message_type, @pytest.mark.parametrize('message_type,enter_signal', [ - (RPCMessageType.BUY_CANCEL, 'long_signal_01'), - (RPCMessageType.SHORT_CANCEL, 'short_signal_01')]) + (RPCMessageType.ENTRY_CANCEL, 'long_signal_01'), + (RPCMessageType.ENTRY_CANCEL, 'short_signal_01')]) def test_send_msg_buy_cancel_notification(default_conf, mocker, message_type, enter_signal) -> None: telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) @@ -1875,14 +1875,14 @@ def test_send_msg_protection_notification(default_conf, mocker, time_machine) -> @pytest.mark.parametrize('message_type,entered,enter_signal,leverage', [ - (RPCMessageType.BUY_FILL, 'Longed', 'long_signal_01', 1.0), - (RPCMessageType.BUY_FILL, 'Longed', 'long_signal_02', 2.0), - (RPCMessageType.SHORT_FILL, 'Shorted', 'short_signal_01', 2.0), + (RPCMessageType.ENTRY_FILL, 'Longed', 'long_signal_01', 1.0), + (RPCMessageType.ENTRY_FILL, 'Longed', 'long_signal_02', 2.0), + (RPCMessageType.ENTRY_FILL, 'Shorted', 'short_signal_01', 2.0), ]) -def test_send_msg_buy_fill_notification(default_conf, mocker, message_type, entered, +def test_send_msg_entry_fill_notification(default_conf, mocker, message_type, entered, enter_signal, leverage) -> None: - default_conf['telegram']['notification_settings']['buy_fill'] = 'on' + default_conf['telegram']['notification_settings']['entry_fill'] = 'on' telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) telegram.send_msg({ @@ -2105,9 +2105,9 @@ def test_send_msg_unknown_type(default_conf, mocker) -> None: @pytest.mark.parametrize('message_type,enter,enter_signal,leverage', [ - (RPCMessageType.BUY, 'Long', 'long_signal_01', None), - (RPCMessageType.BUY, 'Long', 'long_signal_01', 2.0), - (RPCMessageType.SHORT, 'Short', 'short_signal_01', 2.0)]) + (RPCMessageType.ENTRY, 'Long', 'long_signal_01', None), + (RPCMessageType.ENTRY, 'Long', 'long_signal_01', 2.0), + (RPCMessageType.ENTRY, 'Short', 'short_signal_01', 2.0)]) def test_send_msg_buy_notification_no_fiat( default_conf, mocker, message_type, enter, enter_signal, leverage) -> None: del default_conf['fiat_display_currency'] diff --git a/tests/rpc/test_rpc_webhook.py b/tests/rpc/test_rpc_webhook.py index 6dd24b6c5..b46e27361 100644 --- a/tests/rpc/test_rpc_webhook.py +++ b/tests/rpc/test_rpc_webhook.py @@ -74,7 +74,7 @@ def test_send_msg_webhook(default_conf, mocker): msg_mock = MagicMock() mocker.patch("freqtrade.rpc.webhook.Webhook._send_msg", msg_mock) msg = { - 'type': RPCMessageType.BUY, + 'type': RPCMessageType.ENTRY, 'exchange': 'Binance', 'pair': 'ETH/BTC', 'leverage': 1.0, @@ -101,7 +101,7 @@ def test_send_msg_webhook(default_conf, mocker): msg_mock.reset_mock() msg = { - 'type': RPCMessageType.SHORT, + 'type': RPCMessageType.ENTRY, 'exchange': 'Binance', 'pair': 'ETH/BTC', 'leverage': 2.0, @@ -128,7 +128,7 @@ def test_send_msg_webhook(default_conf, mocker): msg_mock.reset_mock() msg = { - 'type': RPCMessageType.BUY_CANCEL, + 'type': RPCMessageType.ENTRY_CANCEL, 'exchange': 'Binance', 'pair': 'ETH/BTC', 'leverage': 1.0, @@ -151,7 +151,7 @@ def test_send_msg_webhook(default_conf, mocker): msg_mock.reset_mock() msg = { - 'type': RPCMessageType.SHORT_CANCEL, + 'type': RPCMessageType.ENTRY_CANCEL, 'exchange': 'Binance', 'pair': 'ETH/BTC', 'leverage': 2.0, @@ -178,7 +178,7 @@ def test_send_msg_webhook(default_conf, mocker): msg_mock.reset_mock() msg = { - 'type': RPCMessageType.BUY_FILL, + 'type': RPCMessageType.ENTRY_FILL, 'exchange': 'Binance', 'pair': 'ETH/BTC', 'leverage': 1.0, @@ -205,7 +205,7 @@ def test_send_msg_webhook(default_conf, mocker): msg_mock.reset_mock() msg = { - 'type': RPCMessageType.SHORT_FILL, + 'type': RPCMessageType.ENTRY_FILL, 'exchange': 'Binance', 'pair': 'ETH/BTC', 'leverage': 2.0, @@ -330,8 +330,8 @@ def test_exception_send_msg(default_conf, mocker, caplog): del default_conf["webhook"]["webhookbuy"] webhook = Webhook(RPC(get_patched_freqtradebot(mocker, default_conf)), default_conf) - webhook.send_msg({'type': RPCMessageType.BUY}) - assert log_has(f"Message type '{RPCMessageType.BUY}' not configured for webhooks", + webhook.send_msg({'type': RPCMessageType.ENTRY}) + assert log_has(f"Message type '{RPCMessageType.ENTRY}' not configured for webhooks", caplog) default_conf["webhook"] = get_webhook_dict() @@ -340,7 +340,7 @@ def test_exception_send_msg(default_conf, mocker, caplog): mocker.patch("freqtrade.rpc.webhook.Webhook._send_msg", msg_mock) webhook = Webhook(RPC(get_patched_freqtradebot(mocker, default_conf)), default_conf) msg = { - 'type': RPCMessageType.BUY, + 'type': RPCMessageType.ENTRY, 'exchange': 'Binance', 'pair': 'ETH/BTC', 'limit': 0.005, diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index f176783ef..66f41a0ac 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -3487,15 +3487,9 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit( assert trade.is_open is False assert trade.exit_reason == ExitType.STOPLOSS_ON_EXCHANGE.value assert rpc_mock.call_count == 3 - 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.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.EXIT + assert rpc_mock.call_args_list[0][0][0]['type'] == RPCMessageType.ENTRY + assert rpc_mock.call_args_list[1][0][0]['type'] == RPCMessageType.ENTRY_FILL + assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.EXIT @pytest.mark.parametrize(