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:
""" Send a message to telegram channel """
noti = self._config['telegram'].get('notification_settings', {}
).get(str(msg['type']), 'on')
default_noti = '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':
logger.info(f"Notification '{msg['type']}' not sent.")
logger.info(f"Notification '{msg_type}' not sent.")
# Notification disabled
return
if msg['type'] == RPCMessageType.BUY:
if msg_type == RPCMessageType.BUY:
message = self._format_buy_msg(msg)
elif msg['type'] in (RPCMessageType.BUY_CANCEL, RPCMessageType.SELL_CANCEL):
msg['message_side'] = 'buy' if msg['type'] == RPCMessageType.BUY_CANCEL else 'sell'
elif msg_type in (RPCMessageType.BUY_CANCEL, RPCMessageType.SELL_CANCEL):
msg['message_side'] = 'buy' if msg_type == RPCMessageType.BUY_CANCEL else 'sell'
message = ("\N{WARNING SIGN} *{exchange}:* "
"Cancelling open {message_side} Order for {pair} (#{trade_id}). "
"Reason: {reason}.".format(**msg))
elif msg['type'] == RPCMessageType.BUY_FILL:
elif msg_type == RPCMessageType.BUY_FILL:
message = ("\N{LARGE CIRCLE} *{exchange}:* "
"Buy order for {pair} (#{trade_id}) filled "
"for {open_rate}.".format(**msg))
elif msg['type'] == RPCMessageType.SELL_FILL:
elif msg_type == RPCMessageType.SELL_FILL:
message = ("\N{LARGE CIRCLE} *{exchange}:* "
"Sell order for {pair} (#{trade_id}) filled "
"for {close_rate}.".format(**msg))
elif msg['type'] == RPCMessageType.SELL:
elif msg_type == RPCMessageType.SELL:
message = self._format_sell_msg(msg)
elif msg['type'] == RPCMessageType.STATUS:
elif msg_type == RPCMessageType.STATUS:
message = '*Status:* `{status}`'.format(**msg)
elif msg['type'] == RPCMessageType.WARNING:
elif msg_type == RPCMessageType.WARNING:
message = '\N{WARNING SIGN} *Warning:* `{status}`'.format(**msg)
elif msg['type'] == RPCMessageType.STARTUP:
elif msg_type == RPCMessageType.STARTUP:
message = '{status}'.format(**msg)
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'))