Merge remote-tracking branch 'upstream/feature/flask-rest' into feature/flask-rest

This commit is contained in:
Matthias
2018-11-25 14:10:08 +01:00
15 changed files with 210 additions and 200 deletions

View File

@@ -16,11 +16,11 @@ app = Flask(__name__)
class ApiServer(RPC):
"""
This class is for REST calls across api server
This class runs api server and provides rpc.rpc functionality to it
This class starts a none blocking thread the api server runs within\
"""
This class starts a none blocking thread the api server runs within
"""
def __init__(self, freqtrade) -> None:
"""
Init the api server, and init the super class RPC

View File

@@ -1,8 +1,8 @@
"""
This module contains class to manage RPC communications (Telegram, Slack, ....)
This module contains class to manage RPC communications (Telegram, Slack, Rest ....)
"""
import logging
from typing import List
from typing import List, Dict
from freqtrade.rpc.rpc import RPC
@@ -18,11 +18,17 @@ class RPCManager(object):
self.registered_modules: List[RPC] = []
# Enable telegram
if freqtrade.config['telegram'].get('enabled', False):
if freqtrade.config.get('telegram', {}).get('enabled', False):
logger.info('Enabling rpc.telegram ...')
from freqtrade.rpc.telegram import Telegram
self.registered_modules.append(Telegram(freqtrade))
# Enable local rest api server for cmd line control
if freqtrade.config.get('api_server', {}).get('enabled', False):
logger.info('Enabling rpc.api_server')
from freqtrade.rpc.api_server import ApiServer
self.registered_modules.append(ApiServer(freqtrade))
def cleanup(self) -> None:
""" Stops all enabled rpc modules """
logger.info('Cleaning up rpc modules ...')
@@ -32,11 +38,14 @@ class RPCManager(object):
mod.cleanup()
del mod
def send_msg(self, msg: str) -> None:
def send_msg(self, msg: Dict[str, str]) -> None:
"""
Send given markdown message to all registered rpc modules
:param msg: message
:return: None
Send given message to all registered rpc modules.
A message consists of one or more key value pairs of strings.
e.g.:
{
'status': 'stopping bot'
}
"""
logger.info('Sending rpc message: %s', msg)
for mod in self.registered_modules:

View File

@@ -4,7 +4,7 @@
This module manage Telegram communication
"""
import logging
from typing import Any, Callable
from typing import Any, Callable, Dict
import arrow
from pandas import DataFrame
@@ -58,10 +58,6 @@ def authorized_only(command_handler: Callable[[Any, Bot, Update], None]) -> Call
class Telegram(RPC):
""" This class handles all telegram communication """
@property
def name(self) -> str:
return "telegram"
def __init__(self, freqtrade) -> None:
"""
Init the Telegram call, and init the super class RPC
@@ -117,9 +113,9 @@ class Telegram(RPC):
"""
self._updater.stop()
def send_msg(self, msg: str) -> None:
def send_msg(self, msg: Dict[str, str]) -> None:
""" Send a message to telegram channel """
self._send_msg(msg)
self._send_msg('*Status:* `{status}`'.format(**msg))
@authorized_only
def _status(self, bot: Bot, update: Update) -> None: