feat: add "*" to define custom default for non-defined exit reasons

This commit is contained in:
Matthias
2024-11-06 20:07:02 +01:00
parent b720ae5d75
commit c58b1f0fd2
2 changed files with 9 additions and 3 deletions

View File

@@ -558,10 +558,12 @@ class Telegram(RPCHandler):
sell_noti = (
self._config["telegram"].get("notification_settings", {}).get(str(msg_type), {})
)
# For backward compatibility sell still can be string
if isinstance(sell_noti, str):
noti = sell_noti
else:
default_noti = sell_noti.get("*", default_noti)
noti = sell_noti.get(str(exit_reason), default_noti)
else:
noti = (

View File

@@ -2912,6 +2912,7 @@ def test_noficiation_settings(default_conf_usdt, mocker):
"exit_fill": {
"roi": "silent",
"partial_exit": "off",
"*": "silent", # Default to silent
},
"exit_cancel": "on",
"protection_trigger": "off",
@@ -2925,15 +2926,18 @@ def test_noficiation_settings(default_conf_usdt, mocker):
assert telegram._message_loudness(RPCMessageType.ENTRY, "") == "silent"
assert telegram._message_loudness(RPCMessageType.ENTRY_FILL, "") == "on"
assert telegram._message_loudness(RPCMessageType.EXIT, "") == "on"
assert telegram._message_loudness(RPCMessageType.EXIT_FILL, "") == "on"
# Default to silent due to "*" definition
assert telegram._message_loudness(RPCMessageType.EXIT_FILL, "") == "silent"
assert telegram._message_loudness(RPCMessageType.PROTECTION_TRIGGER, "") == "off"
assert telegram._message_loudness(RPCMessageType.EXIT, "roi") == "silent"
assert telegram._message_loudness(RPCMessageType.EXIT, "partial_exit") == "off"
# Not given key defaults to on
assert telegram._message_loudness(RPCMessageType.EXIT, "cust_exit112") == "on"
assert telegram._message_loudness(RPCMessageType.EXIT_FILL, "roi") == "silent"
assert telegram._message_loudness(RPCMessageType.EXIT_FILL, "partial_exit") == "off"
# Default to on
assert telegram._message_loudness(RPCMessageType.EXIT_FILL, "cust_exit112") == "on"
# Default to silent due to "*" definition
assert telegram._message_loudness(RPCMessageType.EXIT_FILL, "cust_exit112") == "silent"
# Simplified setup for exit
telegram._config["telegram"].update(