Merge pull request #4015 from freqtrade/dependabot/pip/develop/python-telegram-bot-13.1

Bump python-telegram-bot from 13.0 to 13.1
This commit is contained in:
Matthias 2020-12-02 19:02:10 +01:00 committed by GitHub
commit 01cb676f2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 39 additions and 28 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,7 +505,7 @@ class Telegram(RPC):
:param update: message update
:return: None
"""
if context.args:
pair = context.args[0]
price = float(context.args[1]) if len(context.args) > 1 else None
try:
@ -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'],
keyboard: List[List[Union[str, KeyboardButton]]] = [
['/daily', '/profit', '/balance'],
['/status', '/status table', '/performance'],
['/count', '/start', '/stop', '/help']]
['/count', '/start', '/stop', '/help']
]
reply_markup = ReplyKeyboardMarkup(keyboard)

View File

@ -4,7 +4,7 @@ pandas==1.1.4
ccxt==1.38.55
aiohttp==3.7.3
SQLAlchemy==1.3.20
python-telegram-bot==13.0
python-telegram-bot==13.1
arrow==0.17.0
cachetools==4.1.1
requests==2.25.0

View File

@ -58,7 +58,6 @@ def test__init__(default_conf, mocker) -> None:
mocker.patch('freqtrade.rpc.telegram.Telegram._init', MagicMock())
telegram = Telegram(get_patched_freqtradebot(mocker, default_conf))
assert telegram._updater is None
assert telegram._config == default_conf
@ -881,7 +880,7 @@ def test_forcesell_handle_invalid(default_conf, update, mocker) -> None:
context.args = []
telegram._forcesell(update=update, context=context)
assert msg_mock.call_count == 1
assert 'invalid argument' in msg_mock.call_args_list[0][0][0]
assert "You must specify a trade-id or 'all'." in msg_mock.call_args_list[0][0][0]
# Invalid argument
msg_mock.reset_mock()
@ -1223,8 +1222,14 @@ def test_telegram_trades(mocker, update, default_conf, fee):
telegram._trades(update=update, context=context)
assert "<b>0 recent trades</b>:" in msg_mock.call_args_list[0][0][0]
assert "<pre>" not in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock()
context.args = ['hello']
telegram._trades(update=update, context=context)
assert "<b>0 recent trades</b>:" in msg_mock.call_args_list[0][0][0]
assert "<pre>" not in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock()
create_mock_trades(fee)
context = MagicMock()
@ -1251,7 +1256,7 @@ def test_telegram_delete_trade(mocker, update, default_conf, fee):
context.args = []
telegram._delete_trade(update=update, context=context)
assert "invalid argument" in msg_mock.call_args_list[0][0][0]
assert "Trade-id not set." in msg_mock.call_args_list[0][0][0]
msg_mock.reset_mock()
create_mock_trades(fee)