|
|
|
@@ -24,6 +24,7 @@ from freqtrade.freqtradebot import FreqtradeBot
|
|
|
|
|
from freqtrade.loggers import setup_logging
|
|
|
|
|
from freqtrade.persistence import PairLocks, Trade
|
|
|
|
|
from freqtrade.rpc import RPC
|
|
|
|
|
from freqtrade.rpc.rpc import RPCException
|
|
|
|
|
from freqtrade.rpc.telegram import Telegram, authorized_only
|
|
|
|
|
from tests.conftest import (create_mock_trades, get_patched_freqtradebot, log_has, log_has_re,
|
|
|
|
|
patch_exchange, patch_get_signal, patch_whitelist)
|
|
|
|
@@ -936,7 +937,7 @@ def test_telegram_forcesell_handle(default_conf, update, ticker, fee,
|
|
|
|
|
telegram._forcesell(update=update, context=context)
|
|
|
|
|
|
|
|
|
|
assert msg_mock.call_count == 4
|
|
|
|
|
last_msg = msg_mock.call_args_list[-1][0][0]
|
|
|
|
|
last_msg = msg_mock.call_args_list[-2][0][0]
|
|
|
|
|
assert {
|
|
|
|
|
'type': RPCMessageType.SELL,
|
|
|
|
|
'trade_id': 1,
|
|
|
|
@@ -1000,7 +1001,7 @@ def test_telegram_forcesell_down_handle(default_conf, update, ticker, fee,
|
|
|
|
|
|
|
|
|
|
assert msg_mock.call_count == 4
|
|
|
|
|
|
|
|
|
|
last_msg = msg_mock.call_args_list[-1][0][0]
|
|
|
|
|
last_msg = msg_mock.call_args_list[-2][0][0]
|
|
|
|
|
assert {
|
|
|
|
|
'type': RPCMessageType.SELL,
|
|
|
|
|
'trade_id': 1,
|
|
|
|
@@ -1054,7 +1055,7 @@ def test_forcesell_all_handle(default_conf, update, ticker, fee, mocker) -> None
|
|
|
|
|
|
|
|
|
|
# Called for each trade 2 times
|
|
|
|
|
assert msg_mock.call_count == 8
|
|
|
|
|
msg = msg_mock.call_args_list[1][0][0]
|
|
|
|
|
msg = msg_mock.call_args_list[0][0][0]
|
|
|
|
|
assert {
|
|
|
|
|
'type': RPCMessageType.SELL,
|
|
|
|
|
'trade_id': 1,
|
|
|
|
@@ -1186,8 +1187,8 @@ def test_forcebuy_no_pair(default_conf, update, mocker) -> None:
|
|
|
|
|
assert fbuy_mock.call_count == 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
|
|
|
|
def test_telegram_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
|
|
|
|
|
|
|
|
|
mocker.patch.multiple(
|
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
@@ -1216,8 +1217,8 @@ def test_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
assert '<code>ETH/BTC\t0.00006217 BTC (6.20%) (1)</code>' in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_buy_tag_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
|
|
|
|
def test_telegram_buy_tag_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
|
|
|
|
mocker.patch.multiple(
|
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
|
fetch_ticker=ticker,
|
|
|
|
@@ -1240,15 +1241,27 @@ def test_buy_tag_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
|
|
|
|
|
trade.close_date = datetime.utcnow()
|
|
|
|
|
trade.is_open = False
|
|
|
|
|
|
|
|
|
|
telegram._buy_tag_performance(update=update, context=MagicMock())
|
|
|
|
|
context = MagicMock()
|
|
|
|
|
telegram._buy_tag_performance(update=update, context=context)
|
|
|
|
|
assert msg_mock.call_count == 1
|
|
|
|
|
assert 'Buy Tag Performance' in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
assert '<code>TESTBUY\t0.00006217 BTC (6.20%) (1)</code>' in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
|
|
|
|
|
context.args = [trade.pair]
|
|
|
|
|
telegram._buy_tag_performance(update=update, context=context)
|
|
|
|
|
assert msg_mock.call_count == 2
|
|
|
|
|
|
|
|
|
|
def test_sell_reason_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
|
|
|
|
msg_mock.reset_mock()
|
|
|
|
|
mocker.patch('freqtrade.rpc.rpc.RPC._rpc_buy_tag_performance',
|
|
|
|
|
side_effect=RPCException('Error'))
|
|
|
|
|
telegram._buy_tag_performance(update=update, context=MagicMock())
|
|
|
|
|
|
|
|
|
|
assert msg_mock.call_count == 1
|
|
|
|
|
assert "Error" in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_telegram_sell_reason_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
|
|
|
|
mocker.patch.multiple(
|
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
|
fetch_ticker=ticker,
|
|
|
|
@@ -1271,15 +1284,27 @@ def test_sell_reason_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
|
|
|
|
|
trade.close_date = datetime.utcnow()
|
|
|
|
|
trade.is_open = False
|
|
|
|
|
|
|
|
|
|
telegram._sell_reason_performance(update=update, context=MagicMock())
|
|
|
|
|
context = MagicMock()
|
|
|
|
|
telegram._sell_reason_performance(update=update, context=context)
|
|
|
|
|
assert msg_mock.call_count == 1
|
|
|
|
|
assert 'Sell Reason Performance' in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
assert '<code>TESTSELL\t0.00006217 BTC (6.20%) (1)</code>' in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
context.args = [trade.pair]
|
|
|
|
|
|
|
|
|
|
telegram._sell_reason_performance(update=update, context=context)
|
|
|
|
|
assert msg_mock.call_count == 2
|
|
|
|
|
|
|
|
|
|
msg_mock.reset_mock()
|
|
|
|
|
mocker.patch('freqtrade.rpc.rpc.RPC._rpc_sell_reason_performance',
|
|
|
|
|
side_effect=RPCException('Error'))
|
|
|
|
|
telegram._sell_reason_performance(update=update, context=MagicMock())
|
|
|
|
|
|
|
|
|
|
assert msg_mock.call_count == 1
|
|
|
|
|
assert "Error" in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_mix_tag_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
|
|
|
|
def test_telegram_mix_tag_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
limit_buy_order, limit_sell_order, mocker) -> None:
|
|
|
|
|
mocker.patch.multiple(
|
|
|
|
|
'freqtrade.exchange.Exchange',
|
|
|
|
|
fetch_ticker=ticker,
|
|
|
|
@@ -1305,12 +1330,25 @@ def test_mix_tag_performance_handle(default_conf, update, ticker, fee,
|
|
|
|
|
trade.close_date = datetime.utcnow()
|
|
|
|
|
trade.is_open = False
|
|
|
|
|
|
|
|
|
|
telegram._mix_tag_performance(update=update, context=MagicMock())
|
|
|
|
|
context = MagicMock()
|
|
|
|
|
telegram._mix_tag_performance(update=update, context=context)
|
|
|
|
|
assert msg_mock.call_count == 1
|
|
|
|
|
assert 'Mix Tag Performance' in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
assert ('<code>TESTBUY TESTSELL\t0.00006217 BTC (6.20%) (1)</code>'
|
|
|
|
|
in msg_mock.call_args_list[0][0][0])
|
|
|
|
|
|
|
|
|
|
context.args = [trade.pair]
|
|
|
|
|
telegram._mix_tag_performance(update=update, context=context)
|
|
|
|
|
assert msg_mock.call_count == 2
|
|
|
|
|
|
|
|
|
|
msg_mock.reset_mock()
|
|
|
|
|
mocker.patch('freqtrade.rpc.rpc.RPC._rpc_mix_tag_performance',
|
|
|
|
|
side_effect=RPCException('Error'))
|
|
|
|
|
telegram._mix_tag_performance(update=update, context=MagicMock())
|
|
|
|
|
|
|
|
|
|
assert msg_mock.call_count == 1
|
|
|
|
|
assert "Error" in msg_mock.call_args_list[0][0][0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_count_handle(default_conf, update, ticker, fee, mocker) -> None:
|
|
|
|
|
mocker.patch.multiple(
|
|
|
|
@@ -1851,6 +1889,7 @@ def test_send_msg_sell_fill_notification(default_conf, mocker) -> None:
|
|
|
|
|
'*Sell Reason:* `stop_loss`\n'
|
|
|
|
|
'*Duration:* `1 day, 2:30:00 (1590.0 min)`\n'
|
|
|
|
|
'*Amount:* `1333.33333333`\n'
|
|
|
|
|
'*Open Rate:* `0.00007500`\n'
|
|
|
|
|
'*Close Rate:* `0.00003201`'
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|