BREAK: notification sell by sell reason

This commit is contained in:
Kamontat Chantrachirathumrong 2021-05-26 15:58:31 +07:00 committed by GitHub
parent 8e89d3e6e4
commit 7b0e4bc15d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -233,44 +233,51 @@ class Telegram(RPCHandler):
def send_msg(self, msg: Dict[str, Any]) -> None: def send_msg(self, msg: Dict[str, Any]) -> None:
""" Send a message to telegram channel """ """ Send a message to telegram channel """
noti = self._config['telegram'].get('notification_settings', {} default_noti = 'on'
).get(str(msg['type']), 'on')
msg_type = str(msg['type'])
noti = ''
if msg_type == RPCMessageType.SELL:
noti = self._config['telegram'].get('notification_settings', {}).get(msg_type, {}).get(str(msg['sell_reason']), default_noti)
else:
noti = self._config['telegram'].get('notification_settings', {}).get(msg_type, default_noti)
if noti == 'off': if noti == 'off':
logger.info(f"Notification '{msg['type']}' not sent.") logger.info(f"Notification '{msg_type}' not sent.")
# Notification disabled # Notification disabled
return return
if msg['type'] == RPCMessageType.BUY: if msg_type == RPCMessageType.BUY:
message = self._format_buy_msg(msg) message = self._format_buy_msg(msg)
elif msg['type'] in (RPCMessageType.BUY_CANCEL, RPCMessageType.SELL_CANCEL): elif msg_type in (RPCMessageType.BUY_CANCEL, RPCMessageType.SELL_CANCEL):
msg['message_side'] = 'buy' if msg['type'] == RPCMessageType.BUY_CANCEL else 'sell' msg['message_side'] = 'buy' if msg_type == RPCMessageType.BUY_CANCEL else 'sell'
message = ("\N{WARNING SIGN} *{exchange}:* " message = ("\N{WARNING SIGN} *{exchange}:* "
"Cancelling open {message_side} Order for {pair} (#{trade_id}). " "Cancelling open {message_side} Order for {pair} (#{trade_id}). "
"Reason: {reason}.".format(**msg)) "Reason: {reason}.".format(**msg))
elif msg['type'] == RPCMessageType.BUY_FILL: elif msg_type == RPCMessageType.BUY_FILL:
message = ("\N{LARGE CIRCLE} *{exchange}:* " message = ("\N{LARGE CIRCLE} *{exchange}:* "
"Buy order for {pair} (#{trade_id}) filled " "Buy order for {pair} (#{trade_id}) filled "
"for {open_rate}.".format(**msg)) "for {open_rate}.".format(**msg))
elif msg['type'] == RPCMessageType.SELL_FILL: elif msg_type == RPCMessageType.SELL_FILL:
message = ("\N{LARGE CIRCLE} *{exchange}:* " message = ("\N{LARGE CIRCLE} *{exchange}:* "
"Sell order for {pair} (#{trade_id}) filled " "Sell order for {pair} (#{trade_id}) filled "
"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.STATUS: elif msg_type == RPCMessageType.STATUS:
message = '*Status:* `{status}`'.format(**msg) message = '*Status:* `{status}`'.format(**msg)
elif msg['type'] == RPCMessageType.WARNING: elif msg_type == RPCMessageType.WARNING:
message = '\N{WARNING SIGN} *Warning:* `{status}`'.format(**msg) message = '\N{WARNING SIGN} *Warning:* `{status}`'.format(**msg)
elif msg['type'] == RPCMessageType.STARTUP: elif msg_type == RPCMessageType.STARTUP:
message = '{status}'.format(**msg) message = '{status}'.format(**msg)
else: else:
raise NotImplementedError('Unknown message type: {}'.format(msg['type'])) raise NotImplementedError('Unknown message type: {}'.format(msg_type))
self._send_msg(message, disable_notification=(noti == 'silent')) self._send_msg(message, disable_notification=(noti == 'silent'))