Add pairlock-notification

This commit is contained in:
Matthias 2021-09-20 19:12:59 +02:00
parent 1da091dea3
commit a0fb43c6ca
4 changed files with 34 additions and 2 deletions

View File

@ -11,6 +11,7 @@ class RPCMessageType(Enum):
SELL = 'sell' SELL = 'sell'
SELL_FILL = 'sell_fill' SELL_FILL = 'sell_fill'
SELL_CANCEL = 'sell_cancel' SELL_CANCEL = 'sell_cancel'
PROTECTION_TRIGGER = 'protection_trigger'
def __repr__(self): def __repr__(self):
return self.value return self.value

View File

@ -1292,8 +1292,7 @@ class FreqtradeBot(LoggingMixin):
if not trade.is_open: if not trade.is_open:
if not stoploss_order and not trade.open_order_id: if not stoploss_order and not trade.open_order_id:
self._notify_exit(trade, '', True) self._notify_exit(trade, '', True)
self.protections.stop_per_pair(trade.pair) self.handle_protections(trade.pair)
self.protections.global_stop()
self.wallets.update() self.wallets.update()
elif not trade.open_order_id: elif not trade.open_order_id:
# Buy fill # Buy fill
@ -1301,6 +1300,19 @@ class FreqtradeBot(LoggingMixin):
return False return False
def handle_protections(self, pair: str) -> None:
prot_trig = self.protections.stop_per_pair(pair)
if prot_trig:
msg = {'type': RPCMessageType.PROTECTION_TRIGGER, }
msg.update(prot_trig.to_json())
self.rpc.send_msg(msg)
prot_trig_glb = self.protections.global_stop()
if prot_trig_glb:
msg = {'type': RPCMessageType.PROTECTION_TRIGGER, }
msg.update(prot_trig_glb.to_json())
self.rpc.send_msg(msg)
def apply_fee_conditional(self, trade: Trade, trade_base_currency: str, def apply_fee_conditional(self, trade: Trade, trade_base_currency: str,
amount: float, fee_abs: float) -> float: amount: float, fee_abs: float) -> float:
""" """

View File

@ -281,6 +281,11 @@ class Telegram(RPCHandler):
"for {close_rate}.".format(**msg)) "for {close_rate}.".format(**msg))
elif msg_type == RPCMessageType.SELL: elif msg_type == RPCMessageType.SELL:
message = self._format_sell_msg(msg) message = self._format_sell_msg(msg)
elif msg_type == RPCMessageType.PROTECTION_TRIGGER:
message = (
"*Protection* triggered due to {reason}. "
"{pair} will be locked until {lock_end_time}."
).format(**msg)
elif msg_type == RPCMessageType.STATUS: elif msg_type == RPCMessageType.STATUS:
message = '*Status:* `{status}`'.format(**msg) message = '*Status:* `{status}`'.format(**msg)

View File

@ -1313,6 +1313,20 @@ def test_send_msg_buy_cancel_notification(default_conf, mocker) -> None:
'Reason: cancelled due to timeout.') 'Reason: cancelled due to timeout.')
def test_send_msg_protection_notification(default_conf, mocker, time_machine) -> None:
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
time_machine.move_to("2021-09-01 05:00:00 +00:00")
lock = PairLocks.lock_pair('ETH/BTC', arrow.utcnow().shift(minutes=6).datetime, 'randreason')
msg = {
'type': RPCMessageType.PROTECTION_TRIGGER,
}
msg.update(lock.to_json())
telegram.send_msg(msg)
assert (msg_mock.call_args[0][0] == "*Protection* triggered due to randreason. "
"ETH/BTC will be locked until 2021-09-01 05:10:00.")
def test_send_msg_buy_fill_notification(default_conf, mocker) -> None: def test_send_msg_buy_fill_notification(default_conf, mocker) -> None:
default_conf['telegram']['notification_settings']['buy_fill'] = 'on' default_conf['telegram']['notification_settings']['buy_fill'] = 'on'