Settings notify sell in telegram base on sell reason (#5028)
* BREAK: notification sell by sell reason * Update constants.py * Update telegram.py * Update telegram-usage.md * Update telegram.py * Update telegram.py * Fix test fail * Update config_full.json.example * Update telegram-usage.md * Update telegram.py * Update telegram.py * Update telegram-usage.md * validate value of sell object * Fix linter * Update constants.py * Make telegram sample slightly more positive Co-authored-by: Matthias <xmatthias@outlook.com>
This commit is contained in:
parent
8bef7217ec
commit
c5c323ca88
@ -165,7 +165,16 @@
|
|||||||
"startup": "on",
|
"startup": "on",
|
||||||
"buy": "on",
|
"buy": "on",
|
||||||
"buy_fill": "on",
|
"buy_fill": "on",
|
||||||
"sell": "on",
|
"sell": {
|
||||||
|
"roi": "off",
|
||||||
|
"emergency_sell": "off",
|
||||||
|
"force_sell": "off",
|
||||||
|
"sell_signal": "off",
|
||||||
|
"trailing_stop_loss": "off",
|
||||||
|
"stop_loss": "off",
|
||||||
|
"stoploss_on_exchange": "off",
|
||||||
|
"custom_sell": "off"
|
||||||
|
},
|
||||||
"sell_fill": "on",
|
"sell_fill": "on",
|
||||||
"buy_cancel": "on",
|
"buy_cancel": "on",
|
||||||
"sell_cancel": "on"
|
"sell_cancel": "on"
|
||||||
|
@ -80,14 +80,23 @@ Example configuration showing the different settings:
|
|||||||
"warning": "on",
|
"warning": "on",
|
||||||
"startup": "off",
|
"startup": "off",
|
||||||
"buy": "silent",
|
"buy": "silent",
|
||||||
"sell": "on",
|
"sell": {
|
||||||
|
"roi": "silent",
|
||||||
|
"emergency_sell": "on",
|
||||||
|
"force_sell": "on",
|
||||||
|
"sell_signal": "silent",
|
||||||
|
"trailing_stop_loss": "on",
|
||||||
|
"stop_loss": "on",
|
||||||
|
"stoploss_on_exchange": "on",
|
||||||
|
"custom_sell": "silent"
|
||||||
|
},
|
||||||
"buy_cancel": "silent",
|
"buy_cancel": "silent",
|
||||||
"sell_cancel": "on",
|
"sell_cancel": "on",
|
||||||
"buy_fill": "off",
|
"buy_fill": "off",
|
||||||
"sell_fill": "off"
|
"sell_fill": "off"
|
||||||
},
|
},
|
||||||
"balance_dust_level": 0.01
|
"balance_dust_level": 0.01
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
`buy` notifications are sent when the order is placed, while `buy_fill` notifications are sent when the order is filled on the exchange.
|
`buy` notifications are sent when the order is placed, while `buy_fill` notifications are sent when the order is filled on the exchange.
|
||||||
|
@ -260,7 +260,13 @@ CONF_SCHEMA = {
|
|||||||
'enum': TELEGRAM_SETTING_OPTIONS,
|
'enum': TELEGRAM_SETTING_OPTIONS,
|
||||||
'default': 'off'
|
'default': 'off'
|
||||||
},
|
},
|
||||||
'sell': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS},
|
'sell': {
|
||||||
|
'type': 'object',
|
||||||
|
'additionalProperties': {
|
||||||
|
'type': 'string',
|
||||||
|
'enum': TELEGRAM_SETTING_OPTIONS
|
||||||
|
}
|
||||||
|
},
|
||||||
'sell_cancel': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS},
|
'sell_cancel': {'type': 'string', 'enum': TELEGRAM_SETTING_OPTIONS},
|
||||||
'sell_fill': {
|
'sell_fill': {
|
||||||
'type': 'string',
|
'type': 'string',
|
||||||
|
@ -233,44 +233,58 @@ 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 = msg['type']
|
||||||
|
noti = ''
|
||||||
|
if msg_type == RPCMessageType.SELL:
|
||||||
|
sell_noti = self._config['telegram'] \
|
||||||
|
.get('notification_settings', {}).get(str(msg_type), {})
|
||||||
|
# For backward compatibility sell still be string
|
||||||
|
if isinstance(noti, str):
|
||||||
|
noti = sell_noti
|
||||||
|
else:
|
||||||
|
noti = sell_noti.get(str(msg['sell_reason']), default_noti)
|
||||||
|
else:
|
||||||
|
noti = self._config['telegram'] \
|
||||||
|
.get('notification_settings', {}).get(str(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'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user