From 7d3116f9fbe446a31837f483aa9bef550d7a1d3d Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 4 Apr 2022 19:32:27 +0200 Subject: [PATCH] webhookbuy -> webhookentry --- docs/configuration.md | 6 +- docs/strategy_migration.md | 3 + docs/webhook-config.md | 18 ++--- .../configuration/deprecated_settings.py | 5 ++ freqtrade/constants.py | 6 +- freqtrade/rpc/webhook.py | 6 +- tests/rpc/test_rpc_telegram.py | 2 +- tests/rpc/test_rpc_webhook.py | 66 +++++++++---------- 8 files changed, 61 insertions(+), 51 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index ac63211a7..3733b5b25 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -150,10 +150,12 @@ Mandatory parameters are marked as **Required**, which means that they are requi | `telegram.balance_dust_level` | Dust-level (in stake currency) - currencies with a balance below this will not be shown by `/balance`.
**Datatype:** float | `webhook.enabled` | Enable usage of Webhook notifications
**Datatype:** Boolean | `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.webhookentry` | Payload to send on entry. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String +| `webhook.webhookentrycancel` | Payload to send on entry order cancel. Only required if `webhook.enabled` is `true`. See the [webhook documentation](webhook-config.md) for more details.
**Datatype:** String +| `webhook.webhookentryfill` | Payload to send on entry order filled. 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.webhookexitfill` | Payload to send on exit order filled. 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/strategy_migration.md b/docs/strategy_migration.md index be93f9040..8f1b0fd5d 100644 --- a/docs/strategy_migration.md +++ b/docs/strategy_migration.md @@ -48,6 +48,9 @@ You can use the quick summary as checklist. Please refer to the detailed section * `force_sell` -> `force_exit` * `emergency_sell` -> `emergency_exit` * Webhook terminology changed from "sell" to "exit". + * `webhookbuy` -> `webhookentry` + * `webhookbuyfill` -> `webhookentryfill` + * `webhookbuycancel` -> `webhookentrycancel` * `webhooksell` -> `webhookexit` * `webhooksellfill` -> `webhookexitfill` * `webhooksellcancel` -> `webhookexitcancel` diff --git a/docs/webhook-config.md b/docs/webhook-config.md index 202c63c7e..5f5933b47 100644 --- a/docs/webhook-config.md +++ b/docs/webhook-config.md @@ -10,17 +10,17 @@ Sample configuration (tested using IFTTT). "webhook": { "enabled": true, "url": "https://maker.ifttt.com/trigger//with/key//", - "webhookbuy": { + "webhookentry": { "value1": "Buying {pair}", "value2": "limit {limit:8f}", "value3": "{stake_amount:8f} {stake_currency}" }, - "webhookbuycancel": { + "webhookentrycancel": { "value1": "Cancelling Open Buy Order for {pair}", "value2": "limit {limit:8f}", "value3": "{stake_amount:8f} {stake_currency}" }, - "webhookbuyfill": { + "webhookentryfill": { "value1": "Buy Order for {pair} filled", "value2": "at {open_rate:8f}", "value3": "" @@ -96,9 +96,9 @@ Optional parameters are available to enable automatic retries for webhook messag Different payloads can be configured for different events. Not all fields are necessary, but you should configure at least one of the dicts, otherwise the webhook will never be called. -### Webhookbuy +### Webhookentry -The fields in `webhook.webhookbuy` are filled when the bot executes a long/short. Parameters are filled using string.format. +The fields in `webhook.webhookentry` are filled when the bot executes a long/short. Parameters are filled using string.format. Possible parameters are: * `trade_id` @@ -118,9 +118,9 @@ Possible parameters are: * `current_rate` * `enter_tag` -### Webhookbuycancel +### Webhookentrycancel -The fields in `webhook.webhookbuycancel` are filled when the bot cancels a long/short order. Parameters are filled using string.format. +The fields in `webhook.webhookentrycancel` are filled when the bot cancels a long/short order. Parameters are filled using string.format. Possible parameters are: * `trade_id` @@ -139,9 +139,9 @@ Possible parameters are: * `current_rate` * `enter_tag` -### Webhookbuyfill +### Webhookentryfill -The fields in `webhook.webhookbuyfill` are filled when the bot filled a long/short order. Parameters are filled using string.format. +The fields in `webhook.webhookentryfill` are filled when the bot filled a long/short order. Parameters are filled using string.format. Possible parameters are: * `trade_id` diff --git a/freqtrade/configuration/deprecated_settings.py b/freqtrade/configuration/deprecated_settings.py index 18b51ffac..929b72371 100644 --- a/freqtrade/configuration/deprecated_settings.py +++ b/freqtrade/configuration/deprecated_settings.py @@ -97,6 +97,11 @@ def process_temporary_deprecated_settings(config: Dict[str, Any]) -> None: process_deprecated_setting(config['telegram'], 'notification_settings', 'buy_cancel', 'notification_settings', 'entry_cancel') if config.get('webhook'): + process_deprecated_setting(config, 'webhook', 'webhookbuy', 'webhook', 'webhookentry') + process_deprecated_setting(config, 'webhook', 'webhookbuycancel', + 'webhook', 'webhookentrycancel') + process_deprecated_setting(config, 'webhook', 'webhookbuyfill', + 'webhook', 'webhookentryfill') process_deprecated_setting(config, 'webhook', 'webhooksell', 'webhook', 'webhookexit') process_deprecated_setting(config, 'webhook', 'webhooksellcancel', 'webhook', 'webhookexitcancel') diff --git a/freqtrade/constants.py b/freqtrade/constants.py index b99f017d5..bcdc815bf 100644 --- a/freqtrade/constants.py +++ b/freqtrade/constants.py @@ -327,9 +327,9 @@ CONF_SCHEMA = { 'format': {'type': 'string', 'enum': WEBHOOK_FORMAT_OPTIONS, 'default': 'form'}, 'retries': {'type': 'integer', 'minimum': 0}, 'retry_delay': {'type': 'number', 'minimum': 0}, - 'webhookbuy': {'type': 'object'}, - 'webhookbuycancel': {'type': 'object'}, - 'webhookbuyfill': {'type': 'object'}, + 'webhookentry': {'type': 'object'}, + 'webhookentrycancel': {'type': 'object'}, + 'webhookentryfill': {'type': 'object'}, 'webhookexit': {'type': 'object'}, 'webhookexitcancel': {'type': 'object'}, 'webhookexitfill': {'type': 'object'}, diff --git a/freqtrade/rpc/webhook.py b/freqtrade/rpc/webhook.py index a42929cc4..a2edcbc85 100644 --- a/freqtrade/rpc/webhook.py +++ b/freqtrade/rpc/webhook.py @@ -45,11 +45,11 @@ class Webhook(RPCHandler): try: whconfig = self._config['webhook'] if msg['type'] in [RPCMessageType.ENTRY]: - valuedict = whconfig.get('webhookbuy', None) + valuedict = whconfig.get('webhookentry', None) elif msg['type'] in [RPCMessageType.ENTRY_CANCEL]: - valuedict = whconfig.get('webhookbuycancel', None) + valuedict = whconfig.get('webhookentrycancel', None) elif msg['type'] in [RPCMessageType.ENTRY_FILL]: - valuedict = whconfig.get('webhookbuyfill', None) + valuedict = whconfig.get('webhookentryfill', None) elif msg['type'] == RPCMessageType.EXIT: valuedict = whconfig.get('webhookexit', None) elif msg['type'] == RPCMessageType.EXIT_FILL: diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index ab7d051f4..af08df4c5 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -1880,7 +1880,7 @@ def test_send_msg_protection_notification(default_conf, mocker, time_machine) -> (RPCMessageType.ENTRY_FILL, 'Shorted', 'short_signal_01', 2.0), ]) def test_send_msg_entry_fill_notification(default_conf, mocker, message_type, entered, - enter_signal, leverage) -> None: + enter_signal, leverage) -> None: default_conf['telegram']['notification_settings']['entry_fill'] = 'on' telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf) diff --git a/tests/rpc/test_rpc_webhook.py b/tests/rpc/test_rpc_webhook.py index b46e27361..db357f80f 100644 --- a/tests/rpc/test_rpc_webhook.py +++ b/tests/rpc/test_rpc_webhook.py @@ -15,21 +15,21 @@ def get_webhook_dict() -> dict: return { "enabled": True, "url": "https://maker.ifttt.com/trigger/freqtrade_test/with/key/c764udvJ5jfSlswVRukZZ2/", - "webhookbuy": { + "webhookentry": { "value1": "Buying {pair}", "value2": "limit {limit:8f}", "value3": "{stake_amount:8f} {stake_currency}", "value4": "leverage {leverage:.1f}", "value5": "direction {direction}" }, - "webhookbuycancel": { + "webhookentrycancel": { "value1": "Cancelling Open Buy Order for {pair}", "value2": "limit {limit:8f}", "value3": "{stake_amount:8f} {stake_currency}", "value4": "leverage {leverage:.1f}", "value5": "direction {direction}" }, - "webhookbuyfill": { + "webhookentryfill": { "value1": "Buy Order for {pair} filled", "value2": "at {open_rate:8f}", "value3": "{stake_amount:8f} {stake_currency}", @@ -88,15 +88,15 @@ 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"]["webhookbuy"]["value1"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value1"].format(**msg)) assert (msg_mock.call_args[0][0]["value2"] == - default_conf["webhook"]["webhookbuy"]["value2"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value2"].format(**msg)) assert (msg_mock.call_args[0][0]["value3"] == - default_conf["webhook"]["webhookbuy"]["value3"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value3"].format(**msg)) assert (msg_mock.call_args[0][0]["value4"] == - default_conf["webhook"]["webhookbuy"]["value4"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value4"].format(**msg)) assert (msg_mock.call_args[0][0]["value5"] == - default_conf["webhook"]["webhookbuy"]["value5"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value5"].format(**msg)) # Test short msg_mock.reset_mock() @@ -115,15 +115,15 @@ 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"]["webhookbuy"]["value1"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value1"].format(**msg)) assert (msg_mock.call_args[0][0]["value2"] == - default_conf["webhook"]["webhookbuy"]["value2"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value2"].format(**msg)) assert (msg_mock.call_args[0][0]["value3"] == - default_conf["webhook"]["webhookbuy"]["value3"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value3"].format(**msg)) assert (msg_mock.call_args[0][0]["value4"] == - default_conf["webhook"]["webhookbuy"]["value4"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value4"].format(**msg)) assert (msg_mock.call_args[0][0]["value5"] == - default_conf["webhook"]["webhookbuy"]["value5"].format(**msg)) + default_conf["webhook"]["webhookentry"]["value5"].format(**msg)) # Test buy cancel msg_mock.reset_mock() @@ -142,11 +142,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"]["webhookbuycancel"]["value1"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value1"].format(**msg)) assert (msg_mock.call_args[0][0]["value2"] == - default_conf["webhook"]["webhookbuycancel"]["value2"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value2"].format(**msg)) assert (msg_mock.call_args[0][0]["value3"] == - default_conf["webhook"]["webhookbuycancel"]["value3"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value3"].format(**msg)) # Test short cancel msg_mock.reset_mock() @@ -165,15 +165,15 @@ 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"]["webhookbuycancel"]["value1"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value1"].format(**msg)) assert (msg_mock.call_args[0][0]["value2"] == - default_conf["webhook"]["webhookbuycancel"]["value2"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value2"].format(**msg)) assert (msg_mock.call_args[0][0]["value3"] == - default_conf["webhook"]["webhookbuycancel"]["value3"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value3"].format(**msg)) assert (msg_mock.call_args[0][0]["value4"] == - default_conf["webhook"]["webhookbuycancel"]["value4"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value4"].format(**msg)) assert (msg_mock.call_args[0][0]["value5"] == - default_conf["webhook"]["webhookbuycancel"]["value5"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value5"].format(**msg)) # Test buy fill msg_mock.reset_mock() @@ -192,15 +192,15 @@ 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"]["webhookbuyfill"]["value1"].format(**msg)) + default_conf["webhook"]["webhookentryfill"]["value1"].format(**msg)) assert (msg_mock.call_args[0][0]["value2"] == - default_conf["webhook"]["webhookbuyfill"]["value2"].format(**msg)) + default_conf["webhook"]["webhookentryfill"]["value2"].format(**msg)) assert (msg_mock.call_args[0][0]["value3"] == - default_conf["webhook"]["webhookbuyfill"]["value3"].format(**msg)) + default_conf["webhook"]["webhookentryfill"]["value3"].format(**msg)) assert (msg_mock.call_args[0][0]["value4"] == - default_conf["webhook"]["webhookbuycancel"]["value4"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value4"].format(**msg)) assert (msg_mock.call_args[0][0]["value5"] == - default_conf["webhook"]["webhookbuycancel"]["value5"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value5"].format(**msg)) # Test short fill msg_mock.reset_mock() @@ -219,15 +219,15 @@ 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"]["webhookbuyfill"]["value1"].format(**msg)) + default_conf["webhook"]["webhookentryfill"]["value1"].format(**msg)) assert (msg_mock.call_args[0][0]["value2"] == - default_conf["webhook"]["webhookbuyfill"]["value2"].format(**msg)) + default_conf["webhook"]["webhookentryfill"]["value2"].format(**msg)) assert (msg_mock.call_args[0][0]["value3"] == - default_conf["webhook"]["webhookbuyfill"]["value3"].format(**msg)) + default_conf["webhook"]["webhookentryfill"]["value3"].format(**msg)) assert (msg_mock.call_args[0][0]["value4"] == - default_conf["webhook"]["webhookbuycancel"]["value4"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value4"].format(**msg)) assert (msg_mock.call_args[0][0]["value5"] == - default_conf["webhook"]["webhookbuycancel"]["value5"].format(**msg)) + default_conf["webhook"]["webhookentrycancel"]["value5"].format(**msg)) # Test sell msg_mock.reset_mock() @@ -327,7 +327,7 @@ def test_send_msg_webhook(default_conf, mocker): def test_exception_send_msg(default_conf, mocker, caplog): default_conf["webhook"] = get_webhook_dict() - del default_conf["webhook"]["webhookbuy"] + del default_conf["webhook"]["webhookentry"] webhook = Webhook(RPC(get_patched_freqtradebot(mocker, default_conf)), default_conf) webhook.send_msg({'type': RPCMessageType.ENTRY}) @@ -335,7 +335,7 @@ def test_exception_send_msg(default_conf, mocker, caplog): caplog) default_conf["webhook"] = get_webhook_dict() - default_conf["webhook"]["webhookbuy"]["value1"] = "{DEADBEEF:8f}" + default_conf["webhook"]["webhookentry"]["value1"] = "{DEADBEEF:8f}" msg_mock = MagicMock() mocker.patch("freqtrade.rpc.webhook.Webhook._send_msg", msg_mock) webhook = Webhook(RPC(get_patched_freqtradebot(mocker, default_conf)), default_conf)