Update forcebuy telegram tests

This commit is contained in:
Matthias 2022-01-27 06:31:45 +01:00
parent 0a52d79208
commit 6e72effbf0
2 changed files with 18 additions and 15 deletions

View File

@ -155,8 +155,8 @@ class Telegram(RPCHandler):
CommandHandler('start', self._start), CommandHandler('start', self._start),
CommandHandler('stop', self._stop), CommandHandler('stop', self._stop),
CommandHandler(['forcesell', 'forceexit'], self._forceexit), CommandHandler(['forcesell', 'forceexit'], self._forceexit),
CommandHandler(['forcebuy', 'forcelong'], partial(self._forcebuy, order_side=SignalDirection.LONG)), CommandHandler(['forcebuy', 'forcelong'], partial(self._forceenter, order_side=SignalDirection.LONG)),
CommandHandler('forceshort', partial(self._forcebuy, order_side=SignalDirection.SHORT)), CommandHandler('forceshort', partial(self._forceenter, order_side=SignalDirection.SHORT)),
CommandHandler('trades', self._trades), CommandHandler('trades', self._trades),
CommandHandler('delete', self._delete_trade), CommandHandler('delete', self._delete_trade),
CommandHandler('performance', self._performance), CommandHandler('performance', self._performance),
@ -892,10 +892,10 @@ class Telegram(RPCHandler):
return [buttons[i:i + cols] for i in range(0, len(buttons), cols)] return [buttons[i:i + cols] for i in range(0, len(buttons), cols)]
@authorized_only @authorized_only
def _forcebuy( def _forceenter(
self, update: Update, context: CallbackContext, order_side: SignalDirection) -> None: self, update: Update, context: CallbackContext, order_side: SignalDirection) -> None:
""" """
Handler for /forcebuy <asset> <price>. Handler for /forcelong <asset> <price> and `/forceshort <asset> <price>
Buys a pair trade at the given or current price Buys a pair trade at the given or current price
:param bot: telegram bot :param bot: telegram bot
:param update: message update :param update: message update
@ -1285,7 +1285,7 @@ class Telegram(RPCHandler):
"Optionally takes a rate at which to buy " "Optionally takes a rate at which to buy "
"(only applies to limit orders).` \n" "(only applies to limit orders).` \n"
) )
if self._rpc_._freqtrade.trading_mode != TradingMode.SPOT: if self._rpc._freqtrade.trading_mode != TradingMode.SPOT:
forcebuy_text += ("*/forceshort <pair> [<rate>]:* `Instantly shorts the given pair. " forcebuy_text += ("*/forceshort <pair> [<rate>]:* `Instantly shorts the given pair. "
"Optionally takes a rate at which to sell " "Optionally takes a rate at which to sell "
"(only applies to limit orders).` \n") "(only applies to limit orders).` \n")

View File

@ -19,6 +19,7 @@ from freqtrade import __version__
from freqtrade.constants import CANCEL_REASON from freqtrade.constants import CANCEL_REASON
from freqtrade.edge import PairInfo from freqtrade.edge import PairInfo
from freqtrade.enums import RPCMessageType, RunMode, SellType, State from freqtrade.enums import RPCMessageType, RunMode, SellType, State
from freqtrade.enums.signaltype import SignalDirection
from freqtrade.exceptions import OperationalException from freqtrade.exceptions import OperationalException
from freqtrade.freqtradebot import FreqtradeBot from freqtrade.freqtradebot import FreqtradeBot
from freqtrade.loggers import setup_logging from freqtrade.loggers import setup_logging
@ -93,8 +94,10 @@ def test_telegram_init(default_conf, mocker, caplog) -> None:
assert start_polling.start_polling.call_count == 1 assert start_polling.start_polling.call_count == 1
message_str = ("rpc.telegram is listening for following commands: [['status'], ['profit'], " message_str = ("rpc.telegram is listening for following commands: [['status'], ['profit'], "
"['balance'], ['start'], ['stop'], ['forcesell'], ['forcebuy'], ['trades'], " "['balance'], ['start'], ['stop'], "
"['delete'], ['performance'], ['buys', 'entries'], ['sells'], ['mix_tags'], " "['forcesell', 'forceexit'], ['forcebuy', 'forcelong'], ['forceshort'], "
"['trades'], ['delete'], ['performance'], "
"['buys', 'entries'], ['sells'], ['mix_tags'], "
"['stats'], ['daily'], ['weekly'], ['monthly'], " "['stats'], ['daily'], ['weekly'], ['monthly'], "
"['count'], ['locks'], ['unlock', 'delete_locks'], " "['count'], ['locks'], ['unlock', 'delete_locks'], "
"['reload_config', 'reload_conf'], ['show_config', 'show_conf'], " "['reload_config', 'reload_conf'], ['show_config', 'show_conf'], "
@ -1133,7 +1136,7 @@ def test_forcesell_handle_invalid(default_conf, update, mocker) -> None:
assert 'invalid argument' in msg_mock.call_args_list[0][0][0] assert 'invalid argument' in msg_mock.call_args_list[0][0][0]
def test_forcebuy_handle(default_conf, update, mocker) -> None: def test_forceenter_handle(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
fbuy_mock = MagicMock(return_value=None) fbuy_mock = MagicMock(return_value=None)
@ -1145,7 +1148,7 @@ def test_forcebuy_handle(default_conf, update, mocker) -> None:
# /forcebuy ETH/BTC # /forcebuy ETH/BTC
context = MagicMock() context = MagicMock()
context.args = ["ETH/BTC"] context.args = ["ETH/BTC"]
telegram._forcebuy(update=update, context=context) telegram._forceenter(update=update, context=context, order_side=SignalDirection.LONG)
assert fbuy_mock.call_count == 1 assert fbuy_mock.call_count == 1
assert fbuy_mock.call_args_list[0][0][0] == 'ETH/BTC' assert fbuy_mock.call_args_list[0][0][0] == 'ETH/BTC'
@ -1157,7 +1160,7 @@ def test_forcebuy_handle(default_conf, update, mocker) -> None:
# /forcebuy ETH/BTC 0.055 # /forcebuy ETH/BTC 0.055
context = MagicMock() context = MagicMock()
context.args = ["ETH/BTC", "0.055"] context.args = ["ETH/BTC", "0.055"]
telegram._forcebuy(update=update, context=context) telegram._forceenter(update=update, context=context, order_side=SignalDirection.LONG)
assert fbuy_mock.call_count == 1 assert fbuy_mock.call_count == 1
assert fbuy_mock.call_args_list[0][0][0] == 'ETH/BTC' assert fbuy_mock.call_args_list[0][0][0] == 'ETH/BTC'
@ -1165,20 +1168,20 @@ def test_forcebuy_handle(default_conf, update, mocker) -> None:
assert fbuy_mock.call_args_list[0][0][1] == 0.055 assert fbuy_mock.call_args_list[0][0][1] == 0.055
def test_forcebuy_handle_exception(default_conf, update, mocker) -> None: def test_forceenter_handle_exception(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf) telegram, freqtradebot, msg_mock = get_telegram_testobject(mocker, default_conf)
patch_get_signal(freqtradebot) patch_get_signal(freqtradebot)
update.message.text = '/forcebuy ETH/Nonepair' update.message.text = '/forcebuy ETH/Nonepair'
telegram._forcebuy(update=update, context=MagicMock()) telegram._forceenter(update=update, context=MagicMock(), order_side=SignalDirection.LONG)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert msg_mock.call_args_list[0][0][0] == 'Forceentry not enabled.' assert msg_mock.call_args_list[0][0][0] == 'Forceentry not enabled.'
def test_forcebuy_no_pair(default_conf, update, mocker) -> None: def test_forceenter_no_pair(default_conf, update, mocker) -> None:
mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0) mocker.patch('freqtrade.rpc.rpc.CryptoToFiatConverter._find_price', return_value=15000.0)
fbuy_mock = MagicMock(return_value=None) fbuy_mock = MagicMock(return_value=None)
@ -1190,7 +1193,7 @@ def test_forcebuy_no_pair(default_conf, update, mocker) -> None:
context = MagicMock() context = MagicMock()
context.args = [] context.args = []
telegram._forcebuy(update=update, context=context) telegram._forceenter(update=update, context=context, order_side=SignalDirection.LONG)
assert fbuy_mock.call_count == 0 assert fbuy_mock.call_count == 0
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
@ -1200,7 +1203,7 @@ def test_forcebuy_no_pair(default_conf, update, mocker) -> None:
assert reduce(lambda acc, x: acc + len(x), keyboard, 0) == 4 assert reduce(lambda acc, x: acc + len(x), keyboard, 0) == 4
update = MagicMock() update = MagicMock()
update.callback_query = MagicMock() update.callback_query = MagicMock()
update.callback_query.data = 'XRP/USDT' update.callback_query.data = 'XRP/USDT_||_long'
telegram._forcebuy_inline(update, None) telegram._forcebuy_inline(update, None)
assert fbuy_mock.call_count == 1 assert fbuy_mock.call_count == 1