From 6a0110aa3c15c77b0fb4695fd81ead07b482086e Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 4 Apr 2022 19:05:36 +0200 Subject: [PATCH] Update webhook configuration --- docs/configuration.md | 4 ++-- docs/deprecated.md | 9 ++++++++- docs/strategy_migration.md | 12 ++++++++++++ docs/webhook-config.md | 25 +++++++++++++------------ freqtrade/constants.py | 6 +++--- freqtrade/enums/rpcmessagetype.py | 2 -- freqtrade/rpc/webhook.py | 18 ++++++++++-------- tests/rpc/test_rpc_webhook.py | 18 +++++++++--------- 8 files changed, 57 insertions(+), 37 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 9ed45fff3..ac63211a7 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -152,8 +152,8 @@ Mandatory parameters are marked as **Required**, which means that they are requi | `webhook.url` | URL for the webhook. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String | `webhook.webhookbuy` | Payload to send on buy. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String | `webhook.webhookbuycancel` | Payload to send on buy order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String -| `webhook.webhooksell` | Payload to send on sell. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String -| `webhook.webhooksellcancel` | Payload to send on sell order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String +| `webhook.webhookexit` | Payload to send on exit. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String +| `webhook.webhookexitcancel` | Payload to send on exit order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String | `webhook.webhookstatus` | Payload to send on status calls. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String | `api_server.enabled` | Enable usage of API Server. See the [API Server documentation](rest-api.md) for more details.
**Datatype:** Boolean | `api_server.listen_ip_address` | Bind IP address. See the [API Server documentation](rest-api.md) for more details.
**Datatype:** IPv4 diff --git a/docs/deprecated.md b/docs/deprecated.md index b50eab679..1c929a610 100644 --- a/docs/deprecated.md +++ b/docs/deprecated.md @@ -57,7 +57,14 @@ While we may drop support for the current interface sometime in the future, we w Please follow the [Strategy migration](strategy_migration.md) guide to migrate your strategy to the new format to start using the new functionalities. -### webhooks - `buy_tag` has been renamed to `enter_tag` +### webhooks - changes with 2022.4 + +#### `buy_tag` has been renamed to `enter_tag` This should apply only to your strategy and potentially to webhooks. We will keep a compatibility layer for 1-2 versions (so both `buy_tag` and `enter_tag` will still work), but support for this in webhooks will disappear after that. + +#### Naming changes + +All "sell" occurances in webhook context have been replaced with "exit" configurations. +As a result `webhooksell` became `webhookexit`, `webhooksellfill` became `webhookexitfill` and `webhooksellcancel` became `webhookexitcancel` diff --git a/docs/strategy_migration.md b/docs/strategy_migration.md index 5721537c6..3f14fc300 100644 --- a/docs/strategy_migration.md +++ b/docs/strategy_migration.md @@ -41,6 +41,18 @@ You can use the quick summary as checklist. Please refer to the detailed section * `order_time_in_force` buy -> entry, sell -> exit. * `order_types` buy -> entry, sell -> exit. * `unfilledtimeout` buy -> entry, sell -> exit. +* Terminology changes + * Sell reasons changed to reflect the new naming of "exit" instead of sells. Be careful in your strategy if you're using `exit_reason` checks. + * `sell_signal` -> `exit_signal` + * `custom_sell` -> `custom_exit` + * `force_sell` -> `force_exit` + * `emergency_sell` -> `emergency_exit` + * Webhook terminology changed from "sell" to "exit". + * `webhooksell` -> `webhookexit` + * `webhooksellfill` -> `webhookexitfill` + * `webhooksellcancel` -> `webhookexitcancel` + + ## Extensive explanation diff --git a/docs/webhook-config.md b/docs/webhook-config.md index b974e0041..202c63c7e 100644 --- a/docs/webhook-config.md +++ b/docs/webhook-config.md @@ -25,18 +25,18 @@ Sample configuration (tested using IFTTT). "value2": "at {open_rate:8f}", "value3": "" }, - "webhooksell": { - "value1": "Selling {pair}", + "webhookexit": { + "value1": "Exiting {pair}", "value2": "limit {limit:8f}", "value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})" }, - "webhooksellcancel": { - "value1": "Cancelling Open Sell Order for {pair}", + "webhookexitcancel": { + "value1": "Cancelling Open Exit Order for {pair}", "value2": "limit {limit:8f}", "value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})" }, - "webhooksellfill": { - "value1": "Sell Order for {pair} filled", + "webhookexitfill": { + "value1": "Exit Order for {pair} filled", "value2": "at {close_rate:8f}.", "value3": "" }, @@ -160,8 +160,9 @@ Possible parameters are: * `current_rate` * `enter_tag` -### Webhooksell -The fields in `webhook.webhooksell` are filled when the bot sells a trade. Parameters are filled using string.format. +### Webhookexit + +The fields in `webhook.webhookexit` are filled when the bot exits a trade. Parameters are filled using string.format. Possible parameters are: * `trade_id` @@ -183,9 +184,9 @@ Possible parameters are: * `open_date` * `close_date` -### Webhooksellfill +### Webhookexitfill -The fields in `webhook.webhooksellfill` are filled when the bot fills a sell order (closes a Trae). Parameters are filled using string.format. +The fields in `webhook.webhookexitfill` are filled when the bot fills a exit order (closes a Trade). Parameters are filled using string.format. Possible parameters are: * `trade_id` @@ -208,9 +209,9 @@ Possible parameters are: * `open_date` * `close_date` -### Webhooksellcancel +### Webhookexitcancel -The fields in `webhook.webhooksellcancel` are filled when the bot cancels a sell order. Parameters are filled using string.format. +The fields in `webhook.webhookexitcancel` are filled when the bot cancels a exit order. Parameters are filled using string.format. Possible parameters are: * `trade_id` diff --git a/freqtrade/constants.py b/freqtrade/constants.py index fdf117341..234f4472b 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -330,9 +330,9 @@ CONF_SCHEMA = { 'webhookbuy': {'type': 'object'}, 'webhookbuycancel': {'type': 'object'}, 'webhookbuyfill': {'type': 'object'}, - 'webhooksell': {'type': 'object'}, - 'webhooksellcancel': {'type': 'object'}, - 'webhooksellfill': {'type': 'object'}, + 'webhookexit': {'type': 'object'}, + 'webhookexitcancel': {'type': 'object'}, + 'webhookexitfill': {'type': 'object'}, 'webhookstatus': {'type': 'object'}, }, }, diff --git a/freqtrade/enums/rpcmessagetype.py b/freqtrade/enums/rpcmessagetype.py index 661f9ce5c..39cf1bda5 100644 --- a/freqtrade/enums/rpcmessagetype.py +++ b/freqtrade/enums/rpcmessagetype.py @@ -14,8 +14,6 @@ class RPCMessageType(Enum): SHORT_FILL = 'short_fill' SHORT_CANCEL = 'short_cancel' - # TODO: The below messagetypes should be renamed to "exit"! - # Careful - has an impact on webhooks, therefore needs proper communication SELL = 'sell' SELL_FILL = 'sell_fill' SELL_CANCEL = 'sell_cancel' diff --git a/freqtrade/rpc/webhook.py b/freqtrade/rpc/webhook.py index b0a884a88..5c192377b 100644 --- a/freqtrade/rpc/webhook.py +++ b/freqtrade/rpc/webhook.py @@ -43,23 +43,25 @@ class Webhook(RPCHandler): def send_msg(self, msg: Dict[str, Any]) -> None: """ Send a message to telegram channel """ try: - + whconfig = self._config['webhook'] + # DEPRECATED: Sell terminology if msg['type'] in [RPCMessageType.BUY, RPCMessageType.SHORT]: - valuedict = self._config['webhook'].get('webhookbuy', None) + valuedict = whconfig.get('webhookbuy', None) elif msg['type'] in [RPCMessageType.BUY_CANCEL, RPCMessageType.SHORT_CANCEL]: - valuedict = self._config['webhook'].get('webhookbuycancel', None) + valuedict = whconfig.get('webhookbuycancel', None) elif msg['type'] in [RPCMessageType.BUY_FILL, RPCMessageType.SHORT_FILL]: - valuedict = self._config['webhook'].get('webhookbuyfill', None) + valuedict = whconfig.get('webhookbuyfill', None) elif msg['type'] == RPCMessageType.SELL: - valuedict = self._config['webhook'].get('webhooksell', None) + valuedict = whconfig.get('webhookexit', whconfig.get('webhooksell', None)) elif msg['type'] == RPCMessageType.SELL_FILL: - valuedict = self._config['webhook'].get('webhooksellfill', None) + valuedict = whconfig.get('webhookexitfill', whconfig.get('webhookexitfill', None)) elif msg['type'] == RPCMessageType.SELL_CANCEL: - valuedict = self._config['webhook'].get('webhooksellcancel', None) + valuedict = whconfig.get('webhookexitcancel', + whconfig.get('webhooksellcancel', None)) elif msg['type'] in (RPCMessageType.STATUS, RPCMessageType.STARTUP, RPCMessageType.WARNING): - valuedict = self._config['webhook'].get('webhookstatus', None) + valuedict = whconfig.get('webhookstatus', None) else: raise NotImplementedError('Unknown message type: {}'.format(msg['type'])) if not valuedict: diff --git a/tests/rpc/test_rpc_webhook.py b/tests/rpc/test_rpc_webhook.py index 1d80b58e5..b3c5fee93 100644 --- a/tests/rpc/test_rpc_webhook.py +++ b/tests/rpc/test_rpc_webhook.py @@ -36,17 +36,17 @@ def get_webhook_dict() -> dict: "value4": "leverage {leverage:.1f}", "value5": "direction {direction}" }, - "webhooksell": { + "webhookexit": { "value1": "Selling {pair}", "value2": "limit {limit:8f}", "value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})" }, - "webhooksellcancel": { + "webhookexitcancel": { "value1": "Cancelling Open Sell Order for {pair}", "value2": "limit {limit:8f}", "value3": "profit: {profit_amount:8f} {stake_currency} ({profit_ratio})" }, - "webhooksellfill": { + "webhookexitfill": { "value1": "Sell Order for {pair} filled", "value2": "at {close_rate:8f}", "value3": "" @@ -249,11 +249,11 @@ def test_send_msg_webhook(default_conf, mocker): webhook.send_msg(msg=msg) assert msg_mock.call_count == 1 assert (msg_mock.call_args[0][0]["value1"] == - default_conf["webhook"]["webhooksell"]["value1"].format(**msg)) + default_conf["webhook"]["webhookexit"]["value1"].format(**msg)) assert (msg_mock.call_args[0][0]["value2"] == - default_conf["webhook"]["webhooksell"]["value2"].format(**msg)) + default_conf["webhook"]["webhookexit"]["value2"].format(**msg)) assert (msg_mock.call_args[0][0]["value3"] == - default_conf["webhook"]["webhooksell"]["value3"].format(**msg)) + default_conf["webhook"]["webhookexit"]["value3"].format(**msg)) # Test sell cancel msg_mock.reset_mock() msg = { @@ -299,11 +299,11 @@ def test_send_msg_webhook(default_conf, mocker): webhook.send_msg(msg=msg) assert msg_mock.call_count == 1 assert (msg_mock.call_args[0][0]["value1"] == - default_conf["webhook"]["webhooksellfill"]["value1"].format(**msg)) + default_conf["webhook"]["webhookexitfill"]["value1"].format(**msg)) assert (msg_mock.call_args[0][0]["value2"] == - default_conf["webhook"]["webhooksellfill"]["value2"].format(**msg)) + default_conf["webhook"]["webhookexitfill"]["value2"].format(**msg)) assert (msg_mock.call_args[0][0]["value3"] == - default_conf["webhook"]["webhooksellfill"]["value3"].format(**msg)) + default_conf["webhook"]["webhookexitfill"]["value3"].format(**msg)) for msgtype in [RPCMessageType.STATUS, RPCMessageType.WARNING,