2018-02-13 03:45:59 +00:00
|
|
|
"""
|
|
|
|
This module contains class to manage RPC communications (Telegram, Slack, ...)
|
|
|
|
"""
|
2018-03-25 19:37:14 +00:00
|
|
|
import logging
|
2018-06-08 01:49:09 +00:00
|
|
|
from typing import List
|
2018-02-13 03:45:59 +00:00
|
|
|
|
2018-06-08 01:49:09 +00:00
|
|
|
from freqtrade.rpc.rpc import RPC
|
2018-02-13 03:45:59 +00:00
|
|
|
|
2018-03-25 19:37:14 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2018-02-13 03:45:59 +00:00
|
|
|
class RPCManager(object):
|
|
|
|
"""
|
|
|
|
Class to manage RPC objects (Telegram, Slack, ...)
|
|
|
|
"""
|
|
|
|
def __init__(self, freqtrade) -> None:
|
2018-06-08 01:49:09 +00:00
|
|
|
""" Initializes all enabled rpc modules """
|
|
|
|
self.registered_modules: List[RPC] = []
|
2018-02-13 03:45:59 +00:00
|
|
|
|
2018-06-08 01:49:09 +00:00
|
|
|
# Enable telegram
|
|
|
|
if freqtrade.config['telegram'].get('enabled', False):
|
2018-03-25 19:37:14 +00:00
|
|
|
logger.info('Enabling rpc.telegram ...')
|
2018-06-08 21:50:38 +00:00
|
|
|
from freqtrade.rpc.telegram import Telegram
|
2018-06-08 01:49:09 +00:00
|
|
|
self.registered_modules.append(Telegram(freqtrade))
|
2018-02-13 03:45:59 +00:00
|
|
|
|
|
|
|
def cleanup(self) -> None:
|
2018-06-08 01:49:09 +00:00
|
|
|
""" Stops all enabled rpc modules """
|
2018-06-08 22:58:24 +00:00
|
|
|
logger.info('Cleaning up rpc modules ...')
|
2018-06-08 01:49:09 +00:00
|
|
|
for mod in self.registered_modules:
|
2018-06-08 22:58:24 +00:00
|
|
|
logger.debug('Cleaning up rpc.%s ...', mod.name)
|
2018-06-08 01:49:09 +00:00
|
|
|
mod.cleanup()
|
|
|
|
|
|
|
|
self.registered_modules = []
|
2018-02-13 03:45:59 +00:00
|
|
|
|
|
|
|
def send_msg(self, msg: str) -> None:
|
|
|
|
"""
|
|
|
|
Send given markdown message to all registered rpc modules
|
|
|
|
:param msg: message
|
|
|
|
:return: None
|
|
|
|
"""
|
2018-06-08 01:49:09 +00:00
|
|
|
logger.info('Sending rpc message: %s', msg)
|
|
|
|
for mod in self.registered_modules:
|
|
|
|
logger.debug('Forwarding message to rpc.%s', mod.name)
|
|
|
|
mod.send_msg(msg)
|