Merge pull request #2201 from freqtrade/fix/webhook
sending rpc messages should not stop the bot
This commit is contained in:
commit
a7e45c5a73
@ -56,7 +56,10 @@ class RPCManager(object):
|
|||||||
logger.info('Sending rpc message: %s', msg)
|
logger.info('Sending rpc message: %s', msg)
|
||||||
for mod in self.registered_modules:
|
for mod in self.registered_modules:
|
||||||
logger.debug('Forwarding message to rpc.%s', mod.name)
|
logger.debug('Forwarding message to rpc.%s', mod.name)
|
||||||
|
try:
|
||||||
mod.send_msg(msg)
|
mod.send_msg(msg)
|
||||||
|
except NotImplementedError:
|
||||||
|
logger.error(f"Message type {msg['type']} not implemented by handler {mod.name}.")
|
||||||
|
|
||||||
def startup_messages(self, config, pairlist) -> None:
|
def startup_messages(self, config, pairlist) -> None:
|
||||||
if config.get('dry_run', False):
|
if config.get('dry_run', False):
|
||||||
|
@ -43,7 +43,9 @@ class Webhook(RPC):
|
|||||||
valuedict = self._config['webhook'].get('webhookbuy', None)
|
valuedict = self._config['webhook'].get('webhookbuy', None)
|
||||||
elif msg['type'] == RPCMessageType.SELL_NOTIFICATION:
|
elif msg['type'] == RPCMessageType.SELL_NOTIFICATION:
|
||||||
valuedict = self._config['webhook'].get('webhooksell', None)
|
valuedict = self._config['webhook'].get('webhooksell', None)
|
||||||
elif msg['type'] == RPCMessageType.STATUS_NOTIFICATION:
|
elif msg['type'] in(RPCMessageType.STATUS_NOTIFICATION,
|
||||||
|
RPCMessageType.CUSTOM_NOTIFICATION,
|
||||||
|
RPCMessageType.WARNING_NOTIFICATION):
|
||||||
valuedict = self._config['webhook'].get('webhookstatus', None)
|
valuedict = self._config['webhook'].get('webhookstatus', None)
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError('Unknown message type: {}'.format(msg['type']))
|
raise NotImplementedError('Unknown message type: {}'.format(msg['type']))
|
||||||
|
@ -115,6 +115,22 @@ def test_init_webhook_enabled(mocker, default_conf, caplog) -> None:
|
|||||||
assert 'webhook' in [mod.name for mod in rpc_manager.registered_modules]
|
assert 'webhook' in [mod.name for mod in rpc_manager.registered_modules]
|
||||||
|
|
||||||
|
|
||||||
|
def test_send_msg_webhook_CustomMessagetype(mocker, default_conf, caplog) -> None:
|
||||||
|
caplog.set_level(logging.DEBUG)
|
||||||
|
default_conf['telegram']['enabled'] = False
|
||||||
|
default_conf['webhook'] = {'enabled': True, 'url': "https://DEADBEEF.com"}
|
||||||
|
mocker.patch('freqtrade.rpc.webhook.Webhook.send_msg',
|
||||||
|
MagicMock(side_effect=NotImplementedError))
|
||||||
|
rpc_manager = RPCManager(get_patched_freqtradebot(mocker, default_conf))
|
||||||
|
|
||||||
|
assert 'webhook' in [mod.name for mod in rpc_manager.registered_modules]
|
||||||
|
rpc_manager.send_msg({'type': RPCMessageType.CUSTOM_NOTIFICATION,
|
||||||
|
'status': 'TestMessage'})
|
||||||
|
assert log_has(
|
||||||
|
"Message type RPCMessageType.CUSTOM_NOTIFICATION not implemented by handler webhook.",
|
||||||
|
caplog)
|
||||||
|
|
||||||
|
|
||||||
def test_startupmessages_telegram_enabled(mocker, default_conf, caplog) -> None:
|
def test_startupmessages_telegram_enabled(mocker, default_conf, caplog) -> None:
|
||||||
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
|
telegram_mock = mocker.patch('freqtrade.rpc.telegram.Telegram.send_msg', MagicMock())
|
||||||
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
|
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
|
||||||
|
@ -91,9 +91,12 @@ def test_send_msg(default_conf, mocker):
|
|||||||
assert (msg_mock.call_args[0][0]["value3"] ==
|
assert (msg_mock.call_args[0][0]["value3"] ==
|
||||||
default_conf["webhook"]["webhooksell"]["value3"].format(**msg))
|
default_conf["webhook"]["webhooksell"]["value3"].format(**msg))
|
||||||
|
|
||||||
|
for msgtype in [RPCMessageType.STATUS_NOTIFICATION,
|
||||||
|
RPCMessageType.WARNING_NOTIFICATION,
|
||||||
|
RPCMessageType.CUSTOM_NOTIFICATION]:
|
||||||
# Test notification
|
# Test notification
|
||||||
msg = {
|
msg = {
|
||||||
'type': RPCMessageType.STATUS_NOTIFICATION,
|
'type': msgtype,
|
||||||
'status': 'Unfilled sell order for BTC cancelled due to timeout'
|
'status': 'Unfilled sell order for BTC cancelled due to timeout'
|
||||||
}
|
}
|
||||||
msg_mock = MagicMock()
|
msg_mock = MagicMock()
|
||||||
|
Loading…
Reference in New Issue
Block a user