Merge branch 'develop' into pr/imxuwang/3799

This commit is contained in:
Matthias
2020-12-05 14:06:23 +01:00
64 changed files with 1109 additions and 273 deletions

View File

@@ -5,11 +5,11 @@ This module manage Telegram communication
"""
import json
import logging
from typing import Any, Callable, Dict, List
from typing import Any, Callable, Dict, List, Union
import arrow
from tabulate import tabulate
from telegram import ParseMode, ReplyKeyboardMarkup, Update
from telegram import KeyboardButton, ParseMode, ReplyKeyboardMarkup, Update
from telegram.error import NetworkError, TelegramError
from telegram.ext import CallbackContext, CommandHandler, Updater
from telegram.utils.helpers import escape_markdown
@@ -71,7 +71,7 @@ class Telegram(RPC):
"""
super().__init__(freqtrade)
self._updater: Updater = None
self._updater: Updater
self._config = freqtrade.config
self._init()
if self._config.get('fiat_display_currency', None):
@@ -232,7 +232,7 @@ class Telegram(RPC):
:return: None
"""
if 'table' in context.args:
if context.args and 'table' in context.args:
self._status_table(update, context)
return
@@ -306,7 +306,7 @@ class Telegram(RPC):
stake_cur = self._config['stake_currency']
fiat_disp_cur = self._config.get('fiat_display_currency', '')
try:
timescale = int(context.args[0])
timescale = int(context.args[0]) if context.args else 7
except (TypeError, ValueError, IndexError):
timescale = 7
try:
@@ -486,7 +486,10 @@ class Telegram(RPC):
:return: None
"""
trade_id = context.args[0] if len(context.args) > 0 else None
trade_id = context.args[0] if context.args and len(context.args) > 0 else None
if not trade_id:
self._send_msg("You must specify a trade-id or 'all'.")
return
try:
msg = self._rpc_forcesell(trade_id)
self._send_msg('Forcesell Result: `{result}`'.format(**msg))
@@ -503,13 +506,13 @@ class Telegram(RPC):
:param update: message update
:return: None
"""
pair = context.args[0]
price = float(context.args[1]) if len(context.args) > 1 else None
try:
self._rpc_forcebuy(pair, price)
except RPCException as e:
self._send_msg(str(e))
if context.args:
pair = context.args[0]
price = float(context.args[1]) if len(context.args) > 1 else None
try:
self._rpc_forcebuy(pair, price)
except RPCException as e:
self._send_msg(str(e))
@authorized_only
def _trades(self, update: Update, context: CallbackContext) -> None:
@@ -522,7 +525,7 @@ class Telegram(RPC):
"""
stake_cur = self._config['stake_currency']
try:
nrecent = int(context.args[0])
nrecent = int(context.args[0]) if context.args else 10
except (TypeError, ValueError, IndexError):
nrecent = 10
try:
@@ -555,9 +558,10 @@ class Telegram(RPC):
:param update: message update
:return: None
"""
trade_id = context.args[0] if len(context.args) > 0 else None
try:
if not context.args or len(context.args) == 0:
raise RPCException("Trade-id not set.")
trade_id = int(context.args[0])
msg = self._rpc_delete(trade_id)
self._send_msg((
'`{result_msg}`\n'
@@ -677,7 +681,7 @@ class Telegram(RPC):
"""
try:
try:
limit = int(context.args[0])
limit = int(context.args[0]) if context.args else 10
except (TypeError, ValueError, IndexError):
limit = 10
logs = self._rpc_get_logs(limit)['logs']
@@ -859,7 +863,7 @@ class Telegram(RPC):
f"*Current state:* `{val['state']}`"
)
def _send_msg(self, msg: str, parse_mode: ParseMode = ParseMode.MARKDOWN,
def _send_msg(self, msg: str, parse_mode: str = ParseMode.MARKDOWN,
disable_notification: bool = False) -> None:
"""
Send given markdown message
@@ -869,9 +873,11 @@ class Telegram(RPC):
:return: None
"""
keyboard = [['/daily', '/profit', '/balance'],
['/status', '/status table', '/performance'],
['/count', '/start', '/stop', '/help']]
keyboard: List[List[Union[str, KeyboardButton]]] = [
['/daily', '/profit', '/balance'],
['/status', '/status table', '/performance'],
['/count', '/start', '/stop', '/help']
]
reply_markup = ReplyKeyboardMarkup(keyboard)