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
@rpc_catch_errors
def _trades_delete(self, tradeid):
def _trades_delete(self, tradeid: int):
"""
Handler for DELETE /trades/<tradeid> endpoint.
Removes the trade from the database (tries to cancel open orders first!)

View File

@ -542,7 +542,7 @@ class RPC:
else:
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>.
Delete the given trade and close eventually existing open orders.

View File

@ -5,11 +5,11 @@ This module manage Telegram communication
"""
import json
import logging
from typing import Any, Callable, Dict
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):
@ -231,7 +231,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
@ -305,7 +305,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 0
except (TypeError, ValueError, IndexError):
timescale = 7
try:
@ -485,7 +485,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))
@ -502,13 +505,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:
@ -521,7 +524,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:
@ -554,9 +557,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'
@ -676,7 +680,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']
@ -802,7 +806,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
@ -812,9 +816,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)