Update typing errors

This commit is contained in:
Matthias 2020-12-01 19:55:20 +01:00
parent 14d44b2cd6
commit 36b7edc342
3 changed files with 29 additions and 23 deletions

View File

@ -470,7 +470,7 @@ class ApiServer(RPC):
@require_login @require_login
@rpc_catch_errors @rpc_catch_errors
def _trades_delete(self, tradeid): def _trades_delete(self, tradeid: int):
""" """
Handler for DELETE /trades/<tradeid> endpoint. Handler for DELETE /trades/<tradeid> endpoint.
Removes the trade from the database (tries to cancel open orders first!) Removes the trade from the database (tries to cancel open orders first!)

View File

@ -542,7 +542,7 @@ class RPC:
else: else:
return None return None
def _rpc_delete(self, trade_id: str) -> Dict[str, Union[str, int]]: def _rpc_delete(self, trade_id: int) -> Dict[str, Union[str, int]]:
""" """
Handler for delete <id>. Handler for delete <id>.
Delete the given trade and close eventually existing open orders. Delete the given trade and close eventually existing open orders.

View File

@ -5,11 +5,11 @@ This module manage Telegram communication
""" """
import json import json
import logging import logging
from typing import Any, Callable, Dict from typing import Any, Callable, Dict, List, Union
import arrow import arrow
from tabulate import tabulate 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.error import NetworkError, TelegramError
from telegram.ext import CallbackContext, CommandHandler, Updater from telegram.ext import CallbackContext, CommandHandler, Updater
from telegram.utils.helpers import escape_markdown from telegram.utils.helpers import escape_markdown
@ -71,7 +71,7 @@ class Telegram(RPC):
""" """
super().__init__(freqtrade) super().__init__(freqtrade)
self._updater: Updater = None self._updater: Updater
self._config = freqtrade.config self._config = freqtrade.config
self._init() self._init()
if self._config.get('fiat_display_currency', None): if self._config.get('fiat_display_currency', None):
@ -231,7 +231,7 @@ class Telegram(RPC):
:return: None :return: None
""" """
if 'table' in context.args: if context.args and 'table' in context.args:
self._status_table(update, context) self._status_table(update, context)
return return
@ -305,7 +305,7 @@ class Telegram(RPC):
stake_cur = self._config['stake_currency'] stake_cur = self._config['stake_currency']
fiat_disp_cur = self._config.get('fiat_display_currency', '') fiat_disp_cur = self._config.get('fiat_display_currency', '')
try: try:
timescale = int(context.args[0]) timescale = int(context.args[0]) if context.args else 0
except (TypeError, ValueError, IndexError): except (TypeError, ValueError, IndexError):
timescale = 7 timescale = 7
try: try:
@ -485,7 +485,10 @@ class Telegram(RPC):
:return: None :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: try:
msg = self._rpc_forcesell(trade_id) msg = self._rpc_forcesell(trade_id)
self._send_msg('Forcesell Result: `{result}`'.format(**msg)) self._send_msg('Forcesell Result: `{result}`'.format(**msg))
@ -502,13 +505,13 @@ class Telegram(RPC):
:param update: message update :param update: message update
:return: None :return: None
""" """
if context.args:
pair = context.args[0] pair = context.args[0]
price = float(context.args[1]) if len(context.args) > 1 else None price = float(context.args[1]) if len(context.args) > 1 else None
try: try:
self._rpc_forcebuy(pair, price) self._rpc_forcebuy(pair, price)
except RPCException as e: except RPCException as e:
self._send_msg(str(e)) self._send_msg(str(e))
@authorized_only @authorized_only
def _trades(self, update: Update, context: CallbackContext) -> None: def _trades(self, update: Update, context: CallbackContext) -> None:
@ -521,7 +524,7 @@ class Telegram(RPC):
""" """
stake_cur = self._config['stake_currency'] stake_cur = self._config['stake_currency']
try: try:
nrecent = int(context.args[0]) nrecent = int(context.args[0]) if context.args else 10
except (TypeError, ValueError, IndexError): except (TypeError, ValueError, IndexError):
nrecent = 10 nrecent = 10
try: try:
@ -554,9 +557,10 @@ class Telegram(RPC):
:param update: message update :param update: message update
:return: None :return: None
""" """
trade_id = context.args[0] if len(context.args) > 0 else None
try: 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) msg = self._rpc_delete(trade_id)
self._send_msg(( self._send_msg((
'`{result_msg}`\n' '`{result_msg}`\n'
@ -676,7 +680,7 @@ class Telegram(RPC):
""" """
try: try:
try: try:
limit = int(context.args[0]) limit = int(context.args[0]) if context.args else 10
except (TypeError, ValueError, IndexError): except (TypeError, ValueError, IndexError):
limit = 10 limit = 10
logs = self._rpc_get_logs(limit)['logs'] logs = self._rpc_get_logs(limit)['logs']
@ -802,7 +806,7 @@ class Telegram(RPC):
f"*Current state:* `{val['state']}`" 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: disable_notification: bool = False) -> None:
""" """
Send given markdown message Send given markdown message
@ -812,9 +816,11 @@ class Telegram(RPC):
:return: None :return: None
""" """
keyboard = [['/daily', '/profit', '/balance'], keyboard: List[List[Union[str, KeyboardButton]]] = [
['/status', '/status table', '/performance'], ['/daily', '/profit', '/balance'],
['/count', '/start', '/stop', '/help']] ['/status', '/status table', '/performance'],
['/count', '/start', '/stop', '/help']
]
reply_markup = ReplyKeyboardMarkup(keyboard) reply_markup = ReplyKeyboardMarkup(keyboard)