From c6e121ffb4cde7fa15326d006fc2d0a062146f4d Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 5 Aug 2022 07:17:58 +0200 Subject: [PATCH] Update tests with correct usdt mock trades --- tests/conftest_trades_usdt.py | 4 ++-- tests/rpc/test_rpc.py | 32 +++++++++++++------------- tests/rpc/test_rpc_apiserver.py | 32 +++++++++++++------------- tests/rpc/test_rpc_telegram.py | 40 ++++++++++++++++----------------- 4 files changed, 54 insertions(+), 54 deletions(-) diff --git a/tests/conftest_trades_usdt.py b/tests/conftest_trades_usdt.py index 41d705c01..9a89eaca6 100644 --- a/tests/conftest_trades_usdt.py +++ b/tests/conftest_trades_usdt.py @@ -63,7 +63,7 @@ def mock_trade_usdt_1(fee, is_short: bool): open_rate=10.0, close_rate=8.0, close_profit=-0.2, - close_profit_abs=-4.0, + close_profit_abs=-4.09, exchange='binance', strategy='SampleStrategy', open_order_id=f'prod_exit_1_{direc(is_short)}', @@ -183,7 +183,7 @@ def mock_trade_usdt_3(fee, is_short: bool): open_rate=1.0, close_rate=1.1, close_profit=0.1, - close_profit_abs=9.8425, + close_profit_abs=2.8425, exchange='binance', is_open=False, strategy='StrategyTestV2', diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 02c62e337..4c580c3c2 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -314,10 +314,10 @@ def test__rpc_timeunit_profit(default_conf_usdt, ticker, fee, # {'date': datetime.date(2022, 6, 11), 'abs_profit': 13.8299999, # 'starting_balance': 1055.37, 'rel_profit': 0.0131044, # 'fiat_value': 0.0, 'trade_count': 2} - assert day['abs_profit'] in (0.0, pytest.approx(13.8299999), pytest.approx(-4.0)) - assert day['rel_profit'] in (0.0, pytest.approx(0.01310441), pytest.approx(-0.00377583)) + assert day['abs_profit'] in (0.0, pytest.approx(6.83), pytest.approx(-4.09)) + assert day['rel_profit'] in (0.0, pytest.approx(0.00642902), pytest.approx(-0.00383512)) assert day['trade_count'] in (0, 1, 2) - assert day['starting_balance'] in (pytest.approx(1059.37), pytest.approx(1055.37)) + assert day['starting_balance'] in (pytest.approx(1062.37), pytest.approx(1066.46)) assert day['fiat_value'] in (0.0, ) # ensure first day is current date assert str(days['data'][0]['date']) == str(datetime.utcnow().date()) @@ -435,9 +435,9 @@ def test_rpc_trade_statistics(default_conf_usdt, ticker, fee, mocker) -> None: create_mock_trades_usdt(fee) stats = rpc._rpc_trade_statistics(stake_currency, fiat_display_currency) - assert pytest.approx(stats['profit_closed_coin']) == 9.83 + assert pytest.approx(stats['profit_closed_coin']) == 2.74 assert pytest.approx(stats['profit_closed_percent_mean']) == -1.67 - assert pytest.approx(stats['profit_closed_fiat']) == 10.813 + assert pytest.approx(stats['profit_closed_fiat']) == 3.014 assert pytest.approx(stats['profit_all_coin']) == -77.45964918 assert pytest.approx(stats['profit_all_percent_mean']) == -57.86 assert pytest.approx(stats['profit_all_fiat']) == -85.205614098 @@ -870,9 +870,9 @@ def test_performance_handle(default_conf_usdt, ticker, fee, mocker) -> None: res = rpc._rpc_performance() assert len(res) == 3 - assert res[0]['pair'] == 'XRP/USDT' + assert res[0]['pair'] == 'ETC/USDT' assert res[0]['count'] == 1 - assert res[0]['profit_pct'] == 10.0 + assert res[0]['profit_pct'] == 5.0 def test_enter_tag_performance_handle(default_conf, ticker, fee, mocker) -> None: @@ -896,16 +896,16 @@ def test_enter_tag_performance_handle(default_conf, ticker, fee, mocker) -> None res = rpc._rpc_enter_tag_performance(None) assert len(res) == 3 - assert res[0]['enter_tag'] == 'TEST3' + assert res[0]['enter_tag'] == 'TEST1' assert res[0]['count'] == 1 - assert res[0]['profit_pct'] == 10.0 + assert res[0]['profit_pct'] == 5.0 res = rpc._rpc_enter_tag_performance(None) assert len(res) == 3 - assert res[0]['enter_tag'] == 'TEST3' + assert res[0]['enter_tag'] == 'TEST1' assert res[0]['count'] == 1 - assert res[0]['profit_pct'] == 10.0 + assert res[0]['profit_pct'] == 5.0 def test_enter_tag_performance_handle_2(mocker, default_conf, markets, fee): @@ -956,11 +956,11 @@ def test_exit_reason_performance_handle(default_conf_usdt, ticker, fee, mocker) res = rpc._rpc_exit_reason_performance(None) assert len(res) == 3 - assert res[0]['exit_reason'] == 'roi' + assert res[0]['exit_reason'] == 'exit_signal' assert res[0]['count'] == 1 - assert res[0]['profit_pct'] == 10.0 + assert res[0]['profit_pct'] == 5.0 - assert res[1]['exit_reason'] == 'exit_signal' + assert res[1]['exit_reason'] == 'roi' assert res[2]['exit_reason'] == 'Other' @@ -1012,9 +1012,9 @@ def test_mix_tag_performance_handle(default_conf, ticker, fee, mocker) -> None: res = rpc._rpc_mix_tag_performance(None) assert len(res) == 3 - assert res[0]['mix_tag'] == 'TEST3 roi' + assert res[0]['mix_tag'] == 'TEST1 exit_signal' assert res[0]['count'] == 1 - assert res[0]['profit_pct'] == 10.0 + assert res[0]['profit_pct'] == 5.0 def test_mix_tag_performance_handle_2(mocker, default_conf, markets, fee): diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 57ba8e9f1..c6507d0ae 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -790,22 +790,22 @@ def test_api_profit(botclient, mocker, ticker, fee, markets, is_short, expected) 'first_trade_timestamp': ANY, 'latest_trade_date': '5 minutes ago', 'latest_trade_timestamp': ANY, - 'profit_all_coin': expected['profit_all_coin'], - 'profit_all_fiat': expected['profit_all_fiat'], - 'profit_all_percent_mean': expected['profit_all_percent_mean'], - 'profit_all_ratio_mean': expected['profit_all_ratio_mean'], - 'profit_all_percent_sum': expected['profit_all_percent_sum'], - 'profit_all_ratio_sum': expected['profit_all_ratio_sum'], - 'profit_all_percent': expected['profit_all_percent'], - 'profit_all_ratio': expected['profit_all_ratio'], - 'profit_closed_coin': expected['profit_closed_coin'], - 'profit_closed_fiat': expected['profit_closed_fiat'], - 'profit_closed_ratio_mean': expected['profit_closed_ratio_mean'], - 'profit_closed_percent_mean': expected['profit_closed_percent_mean'], - 'profit_closed_ratio_sum': expected['profit_closed_ratio_sum'], - 'profit_closed_percent_sum': expected['profit_closed_percent_sum'], - 'profit_closed_ratio': expected['profit_closed_ratio'], - 'profit_closed_percent': expected['profit_closed_percent'], + 'profit_all_coin': pytest.approx(expected['profit_all_coin']), + 'profit_all_fiat': pytest.approx(expected['profit_all_fiat']), + 'profit_all_percent_mean': pytest.approx(expected['profit_all_percent_mean']), + 'profit_all_ratio_mean': pytest.approx(expected['profit_all_ratio_mean']), + 'profit_all_percent_sum': pytest.approx(expected['profit_all_percent_sum']), + 'profit_all_ratio_sum': pytest.approx(expected['profit_all_ratio_sum']), + 'profit_all_percent': pytest.approx(expected['profit_all_percent']), + 'profit_all_ratio': pytest.approx(expected['profit_all_ratio']), + 'profit_closed_coin': pytest.approx(expected['profit_closed_coin']), + 'profit_closed_fiat': pytest.approx(expected['profit_closed_fiat']), + 'profit_closed_ratio_mean': pytest.approx(expected['profit_closed_ratio_mean']), + 'profit_closed_percent_mean': pytest.approx(expected['profit_closed_percent_mean']), + 'profit_closed_ratio_sum': pytest.approx(expected['profit_closed_ratio_sum']), + 'profit_closed_percent_sum': pytest.approx(expected['profit_closed_percent_sum']), + 'profit_closed_ratio': pytest.approx(expected['profit_closed_ratio']), + 'profit_closed_percent': pytest.approx(expected['profit_closed_percent']), 'trade_count': 6, 'closed_trade_count': 2, 'winning_trades': expected['winning_trades'], diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index 98c06c8e9..9508a6b42 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -433,10 +433,10 @@ def test_daily_handle(default_conf_usdt, update, ticker, fee, mocker, time_machi assert "Daily Profit over the last 2 days:" in msg_mock.call_args_list[0][0][0] assert 'Day ' in msg_mock.call_args_list[0][0][0] assert str(datetime.utcnow().date()) in msg_mock.call_args_list[0][0][0] - assert ' 13.83 USDT' in msg_mock.call_args_list[0][0][0] - assert ' 15.21 USD' in msg_mock.call_args_list[0][0][0] + assert ' 6.83 USDT' in msg_mock.call_args_list[0][0][0] + assert ' 7.51 USD' in msg_mock.call_args_list[0][0][0] assert '(2)' in msg_mock.call_args_list[0][0][0] - assert '(2) 13.83 USDT 15.21 USD 1.31%' in msg_mock.call_args_list[0][0][0] + assert '(2) 6.83 USDT 7.51 USD 0.64%' in msg_mock.call_args_list[0][0][0] assert '(0)' in msg_mock.call_args_list[0][0][0] # Reset msg_mock @@ -447,8 +447,8 @@ def test_daily_handle(default_conf_usdt, update, ticker, fee, mocker, time_machi assert "Daily Profit over the last 7 days:" in msg_mock.call_args_list[0][0][0] assert str(datetime.utcnow().date()) in msg_mock.call_args_list[0][0][0] assert str((datetime.utcnow() - timedelta(days=5)).date()) in msg_mock.call_args_list[0][0][0] - assert ' 13.83 USDT' in msg_mock.call_args_list[0][0][0] - assert ' 15.21 USD' in msg_mock.call_args_list[0][0][0] + assert ' 6.83 USDT' in msg_mock.call_args_list[0][0][0] + assert ' 7.51 USD' in msg_mock.call_args_list[0][0][0] assert '(2)' in msg_mock.call_args_list[0][0][0] assert '(1)' in msg_mock.call_args_list[0][0][0] assert '(0)' in msg_mock.call_args_list[0][0][0] @@ -460,8 +460,8 @@ def test_daily_handle(default_conf_usdt, update, ticker, fee, mocker, time_machi context = MagicMock() context.args = ["1"] telegram._daily(update=update, context=context) - assert ' 13.83 USDT' in msg_mock.call_args_list[0][0][0] - assert ' 15.21 USD' in msg_mock.call_args_list[0][0][0] + assert ' 6.83 USDT' in msg_mock.call_args_list[0][0][0] + assert ' 7.51 USD' in msg_mock.call_args_list[0][0][0] assert '(2)' in msg_mock.call_args_list[0][0][0] @@ -523,8 +523,8 @@ def test_weekly_handle(default_conf_usdt, update, ticker, fee, mocker, time_mach today = datetime.utcnow().date() first_iso_day_of_current_week = today - timedelta(days=today.weekday()) assert str(first_iso_day_of_current_week) in msg_mock.call_args_list[0][0][0] - assert ' 9.83 USDT' in msg_mock.call_args_list[0][0][0] - assert ' 10.81 USD' in msg_mock.call_args_list[0][0][0] + assert ' 2.74 USDT' in msg_mock.call_args_list[0][0][0] + assert ' 3.01 USD' in msg_mock.call_args_list[0][0][0] assert '(3)' in msg_mock.call_args_list[0][0][0] assert '(0)' in msg_mock.call_args_list[0][0][0] @@ -536,8 +536,8 @@ def test_weekly_handle(default_conf_usdt, update, ticker, fee, mocker, time_mach assert "Weekly Profit over the last 8 weeks (starting from Monday):" \ in msg_mock.call_args_list[0][0][0] assert 'Weekly' in msg_mock.call_args_list[0][0][0] - assert ' 9.83 USDT' in msg_mock.call_args_list[0][0][0] - assert ' 10.81 USD' in msg_mock.call_args_list[0][0][0] + assert ' 2.74 USDT' in msg_mock.call_args_list[0][0][0] + assert ' 3.01 USD' in msg_mock.call_args_list[0][0][0] assert '(3)' in msg_mock.call_args_list[0][0][0] assert '(0)' in msg_mock.call_args_list[0][0][0] @@ -592,8 +592,8 @@ def test_monthly_handle(default_conf_usdt, update, ticker, fee, mocker, time_mac today = datetime.utcnow().date() current_month = f"{today.year}-{today.month:02} " assert current_month in msg_mock.call_args_list[0][0][0] - assert ' 9.83 USDT' in msg_mock.call_args_list[0][0][0] - assert ' 10.81 USD' in msg_mock.call_args_list[0][0][0] + assert ' 2.74 USDT' in msg_mock.call_args_list[0][0][0] + assert ' 3.01 USD' in msg_mock.call_args_list[0][0][0] assert '(3)' in msg_mock.call_args_list[0][0][0] assert '(0)' in msg_mock.call_args_list[0][0][0] @@ -606,8 +606,8 @@ def test_monthly_handle(default_conf_usdt, update, ticker, fee, mocker, time_mac assert 'Monthly Profit over the last 6 months:' in msg_mock.call_args_list[0][0][0] assert 'Month ' in msg_mock.call_args_list[0][0][0] assert current_month in msg_mock.call_args_list[0][0][0] - assert ' 9.83 USDT' in msg_mock.call_args_list[0][0][0] - assert ' 10.81 USD' in msg_mock.call_args_list[0][0][0] + assert ' 2.74 USDT' in msg_mock.call_args_list[0][0][0] + assert ' 3.01 USD' in msg_mock.call_args_list[0][0][0] assert '(3)' in msg_mock.call_args_list[0][0][0] assert '(0)' in msg_mock.call_args_list[0][0][0] @@ -620,8 +620,8 @@ def test_monthly_handle(default_conf_usdt, update, ticker, fee, mocker, time_mac telegram._monthly(update=update, context=context) assert msg_mock.call_count == 1 assert 'Monthly Profit over the last 12 months:' in msg_mock.call_args_list[0][0][0] - assert ' 9.83 USDT' in msg_mock.call_args_list[0][0][0] - assert ' 10.81 USD' in msg_mock.call_args_list[0][0][0] + assert ' 2.74 USDT' in msg_mock.call_args_list[0][0][0] + assert ' 3.01 USD' in msg_mock.call_args_list[0][0][0] assert '(3)' in msg_mock.call_args_list[0][0][0] # The one-digit months should contain a zero, Eg: September 2021 = "2021-09" @@ -1268,7 +1268,7 @@ def test_telegram_performance_handle(default_conf_usdt, update, ticker, fee, moc telegram._performance(update=update, context=MagicMock()) assert msg_mock.call_count == 1 assert 'Performance' in msg_mock.call_args_list[0][0][0] - assert 'XRP/USDT\t9.842 USDT (10.00%) (1)' in msg_mock.call_args_list[0][0][0] + assert 'XRP/USDT\t2.842 USDT (10.00%) (1)' in msg_mock.call_args_list[0][0][0] def test_telegram_entry_tag_performance_handle( @@ -1318,7 +1318,7 @@ def test_telegram_exit_reason_performance_handle(default_conf_usdt, update, tick telegram._exit_reason_performance(update=update, context=context) assert msg_mock.call_count == 1 assert 'Exit Reason Performance' in msg_mock.call_args_list[0][0][0] - assert 'roi\t9.842 USDT (10.00%) (1)' in msg_mock.call_args_list[0][0][0] + assert 'roi\t2.842 USDT (10.00%) (1)' in msg_mock.call_args_list[0][0][0] context.args = ['XRP/USDT'] telegram._exit_reason_performance(update=update, context=context) @@ -1350,7 +1350,7 @@ def test_telegram_mix_tag_performance_handle(default_conf_usdt, update, ticker, 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 ('TEST3 roi\t9.842 USDT (10.00%) (1)' + assert ('TEST3 roi\t2.842 USDT (10.00%) (1)' in msg_mock.call_args_list[0][0][0]) context.args = ['XRP/USDT']