Skip to content

Commit

Permalink
Split protection-notification into global and per-pair
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Sep 20, 2021
1 parent a0fb43c commit dd0db7e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion config_examples/config_full.example.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,9 @@
},
"sell_fill": "on",
"buy_cancel": "on",
"sell_cancel": "on"
"sell_cancel": "on",
"protection_trigger": "off",
"protection_trigger_global": "on"
},
"reload": true,
"balance_dust_level": 0.01
Expand Down
4 changes: 3 additions & 1 deletion docs/telegram-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ Example configuration showing the different settings:
"buy_cancel": "silent",
"sell_cancel": "on",
"buy_fill": "off",
"sell_fill": "off"
"sell_fill": "off",
"protection_trigger": "off",
"protection_trigger_global": "on"
},
"reload": true,
"balance_dust_level": 0.01
Expand Down
1 change: 1 addition & 0 deletions freqtrade/enums/rpcmessagetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class RPCMessageType(Enum):
SELL_FILL = 'sell_fill'
SELL_CANCEL = 'sell_cancel'
PROTECTION_TRIGGER = 'protection_trigger'
PROTECTION_TRIGGER_GLOBAL = 'protection_trigger_global'

def __repr__(self):
return self.value
Expand Down
2 changes: 1 addition & 1 deletion freqtrade/freqtradebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1309,7 +1309,7 @@ def handle_protections(self, pair: str) -> None:

prot_trig_glb = self.protections.global_stop()
if prot_trig_glb:
msg = {'type': RPCMessageType.PROTECTION_TRIGGER, }
msg = {'type': RPCMessageType.PROTECTION_TRIGGER_GLOBAL, }
msg.update(prot_trig_glb.to_json())
self.rpc.send_msg(msg)

Expand Down
6 changes: 5 additions & 1 deletion freqtrade/rpc/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ def compose_message(self, msg: Dict[str, Any], msg_type: RPCMessageType) -> str:
"*Protection* triggered due to {reason}. "
"{pair} will be locked until {lock_end_time}."
).format(**msg)

elif msg_type == RPCMessageType.PROTECTION_TRIGGER_GLOBAL:
message = (
"*Protection* triggered due to {reason}. "
"All pairs will be locked until {lock_end_time}."
).format(**msg)
elif msg_type == RPCMessageType.STATUS:
message = '*Status:* `{status}`'.format(**msg)

Expand Down
13 changes: 13 additions & 0 deletions tests/rpc/test_rpc_telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,19 @@ def test_send_msg_protection_notification(default_conf, mocker, time_machine) ->
assert (msg_mock.call_args[0][0] == "*Protection* triggered due to randreason. "
"ETH/BTC will be locked until 2021-09-01 05:10:00.")

msg_mock.reset_mock()
# Test global protection

msg = {
'type': RPCMessageType.PROTECTION_TRIGGER_GLOBAL,
}
lock = PairLocks.lock_pair('*', arrow.utcnow().shift(minutes=100).datetime, 'randreason')
msg.update(lock.to_json())
telegram.send_msg(msg)
assert (msg_mock.call_args[0][0] == "*Protection* triggered due to randreason. "
"All pairs will be locked until 2021-09-01 06:45:00.")



def test_send_msg_buy_fill_notification(default_conf, mocker) -> None:

Expand Down

0 comments on commit dd0db7e

Please sign in to comment.