From 268b191cc282de7dfb330df81b546e3776ff3a1b Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 May 2022 20:16:59 +0200 Subject: [PATCH] Revert some pointless changes. --- tests/rpc/test_rpc.py | 36 +++++++----------- tests/rpc/test_rpc_telegram.py | 68 +++++++++++++++++----------------- tests/test_freqtradebot.py | 3 +- tests/test_persistence.py | 4 +- 4 files changed, 49 insertions(+), 62 deletions(-) diff --git a/tests/rpc/test_rpc.py b/tests/rpc/test_rpc.py index 61cf3f7dd..090ea581c 100644 --- a/tests/rpc/test_rpc.py +++ b/tests/rpc/test_rpc.py @@ -310,7 +310,6 @@ def test_rpc_daily_profit(default_conf, update, ticker, fee, # Simulate buy & sell oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') - trade.orders[0] = oobj trade.update_trade(oobj) oobj = Order.parse_from_ccxt_object(limit_sell_order, limit_sell_order['symbol'], 'sell') trade.update_trade(oobj) @@ -453,7 +452,6 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee, trade = Trade.query.first() # Simulate fulfilled LIMIT_BUY order for trade oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') - trade.orders[0] = oobj trade.update_trade(oobj) # Update the ticker with a market going up @@ -467,23 +465,20 @@ def test_rpc_trade_statistics(default_conf, ticker, ticker_sell_up, fee, trade.is_open = False freqtradebot.enter_positions() - - # TODO: updated the first trade again - # trade = Trade.query.first() - # # Simulate fulfilled LIMIT_BUY order for trade - # oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') - # trade.orders[0] = oobj - # trade.update_trade(oobj) + trade = Trade.query.first() + # Simulate fulfilled LIMIT_BUY order for trade + oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') + trade.update_trade(oobj) # Update the ticker with a market going up - # mocker.patch.multiple( - # 'freqtrade.exchange.Exchange', - # fetch_ticker=ticker_sell_up - # ) - # oobj = Order.parse_from_ccxt_object(limit_sell_order, limit_sell_order['symbol'], 'sell') - # trade.update_trade(oobj) - # trade.close_date = datetime.utcnow() - # trade.is_open = False + mocker.patch.multiple( + 'freqtrade.exchange.Exchange', + fetch_ticker=ticker_sell_up + ) + oobj = Order.parse_from_ccxt_object(limit_sell_order, limit_sell_order['symbol'], 'sell') + trade.update_trade(oobj) + trade.close_date = datetime.utcnow() + trade.is_open = False stats = rpc._rpc_trade_statistics(stake_currency, fiat_display_currency) assert prec_satoshi(stats['profit_closed_coin'], 6.217e-05) @@ -541,7 +536,6 @@ def test_rpc_trade_statistics_closed(mocker, default_conf, ticker, fee, trade = Trade.query.first() # Simulate fulfilled LIMIT_BUY order for trade oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') - trade.orders[0] = oobj trade.update_trade(oobj) # Update the ticker with a market going up mocker.patch.multiple( @@ -913,7 +907,7 @@ def test_rpc_force_exit(default_conf, ticker, fee, mocker) -> None: 'amount': amount, 'remaining': amount, 'filled': 0.0, - 'id': trade.orders[0].order_id + 'id': trade.orders[0].order_id, } ) msg = rpc._rpc_force_exit('3') @@ -943,7 +937,6 @@ def test_performance_handle(default_conf, ticker, limit_buy_order, fee, # Simulate fulfilled LIMIT_BUY order for trade oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') - trade.orders[0] = oobj trade.update_trade(oobj) # Simulate fulfilled LIMIT_SELL order for trade @@ -980,7 +973,6 @@ def test_enter_tag_performance_handle(default_conf, ticker, limit_buy_order, fee # Simulate fulfilled LIMIT_BUY order for trade oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') - trade.orders[0] = oobj trade.update_trade(oobj) # Simulate fulfilled LIMIT_SELL order for trade @@ -1055,7 +1047,6 @@ def test_exit_reason_performance_handle(default_conf, ticker, limit_buy_order, f # Simulate fulfilled LIMIT_BUY order for trade oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') - trade.orders[0] = oobj trade.update_trade(oobj) # Simulate fulfilled LIMIT_SELL order for trade @@ -1130,7 +1121,6 @@ def test_mix_tag_performance_handle(default_conf, ticker, limit_buy_order, fee, # Simulate fulfilled LIMIT_BUY order for trade oobj = Order.parse_from_ccxt_object(limit_buy_order, limit_buy_order['symbol'], 'buy') - trade.orders[0] = oobj trade.update_trade(oobj) # Simulate fulfilled LIMIT_SELL order for trade diff --git a/tests/rpc/test_rpc_telegram.py b/tests/rpc/test_rpc_telegram.py index dc392c748..5499e09bb 100644 --- a/tests/rpc/test_rpc_telegram.py +++ b/tests/rpc/test_rpc_telegram.py @@ -474,7 +474,6 @@ def test_daily_handle(default_conf, update, ticker, limit_buy_order, fee, trades = Trade.query.all() for trade in trades: - trade.orders[0] = oobj trade.update_trade(oobj) trade.update_trade(oobjs) trade.close_date = datetime.utcnow() @@ -592,7 +591,6 @@ def test_weekly_handle(default_conf, update, ticker, limit_buy_order, fee, trades = Trade.query.all() for trade in trades: - trade.orders[0] = oobj trade.update_trade(oobj) trade.update_trade(oobjs) trade.close_date = datetime.utcnow() @@ -713,7 +711,6 @@ def test_monthly_handle(default_conf, update, ticker, limit_buy_order, fee, trades = Trade.query.all() for trade in trades: - trade.orders[0] = oobj trade.update_trade(oobj) trade.update_trade(oobjs) trade.close_date = datetime.utcnow() @@ -2000,14 +1997,15 @@ def test_send_msg_entry_fill_notification(default_conf, mocker, message_type, en 'open_date': arrow.utcnow().shift(hours=-1) }) - assert msg_mock.call_args[0][0] \ - == f'\N{CHECK MARK} *Binance:* {entered}ed ETH/BTC (#1)\n' \ - f'*Enter Tag:* `{enter_signal}`\n' \ - '*Amount:* `1333.33333333`\n' \ - f"{leverage_text}" \ - '*Open Rate:* `0.00001099`\n' \ - '*Total:* `(0.01465333 BTC, 180.895 USD)`\n' \ - '*Balance:* `(0.01465333 BTC, 180.895 USD)`' + assert msg_mock.call_args[0][0] == ( + f'\N{CHECK MARK} *Binance:* {entered}ed ETH/BTC (#1)\n' + f'*Enter Tag:* `{enter_signal}`\n' + '*Amount:* `1333.33333333`\n' + f"{leverage_text}" + '*Open Rate:* `0.00001099`\n' + '*Total:* `(0.01465333 BTC, 180.895 USD)`\n' + '*Balance:* `(0.01465333 BTC, 180.895 USD)`' + ) def test_send_msg_sell_notification(default_conf, mocker) -> None: @@ -2076,18 +2074,18 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None: 'stake_amount': 1234, 'sub_trade': True }) - assert msg_mock.call_args[0][0] \ - == ('\N{WARNING SIGN} *Binance:* Exiting KEY/ETH (#1)\n' - '*Unrealized Cumulative Profit:* `-57.41% (loss: -0.05746268 ETH / -24.812 USD)`\n' - '*Enter Tag:* `buy_signal1`\n' - '*Exit Reason:* `stop_loss`\n' - '*Direction:* `Long`\n' - '*Amount:* `1333.33333333`\n' - '*Open Rate:* `0.00007500`\n' - '*Current Rate:* `0.00003201`\n' - '*Close Rate:* `0.00003201`\n' - '*Remaining:* `(1234 ETH, -24.812 USD)`' - ) + assert msg_mock.call_args[0][0] == ( + '\N{WARNING SIGN} *Binance:* Exiting KEY/ETH (#1)\n' + '*Unrealized Cumulative Profit:* `-57.41% (loss: -0.05746268 ETH / -24.812 USD)`\n' + '*Enter Tag:* `buy_signal1`\n' + '*Exit Reason:* `stop_loss`\n' + '*Direction:* `Long`\n' + '*Amount:* `1333.33333333`\n' + '*Open Rate:* `0.00007500`\n' + '*Current Rate:* `0.00003201`\n' + '*Close Rate:* `0.00003201`\n' + '*Remaining:* `(1234 ETH, -24.812 USD)`' + ) msg_mock.reset_mock() telegram.send_msg({ @@ -2110,18 +2108,18 @@ def test_send_msg_sell_notification(default_conf, mocker) -> None: 'open_date': arrow.utcnow().shift(days=-1, hours=-2, minutes=-30), 'close_date': arrow.utcnow(), }) - assert msg_mock.call_args[0][0] \ - == ('\N{WARNING SIGN} *Binance:* Exiting KEY/ETH (#1)\n' - '*Unrealized Profit:* `-57.41% (loss: -0.05746268 ETH)`\n' - '*Enter Tag:* `buy_signal1`\n' - '*Exit Reason:* `stop_loss`\n' - '*Direction:* `Long`\n' - '*Amount:* `1333.33333333`\n' - '*Open Rate:* `0.00007500`\n' - '*Current Rate:* `0.00003201`\n' - '*Close Rate:* `0.00003201`\n' - '*Duration:* `1 day, 2:30:00 (1590.0 min)`' - ) + assert msg_mock.call_args[0][0] == ( + '\N{WARNING SIGN} *Binance:* Exiting KEY/ETH (#1)\n' + '*Unrealized Profit:* `-57.41% (loss: -0.05746268 ETH)`\n' + '*Enter Tag:* `buy_signal1`\n' + '*Exit Reason:* `stop_loss`\n' + '*Direction:* `Long`\n' + '*Amount:* `1333.33333333`\n' + '*Open Rate:* `0.00007500`\n' + '*Current Rate:* `0.00003201`\n' + '*Close Rate:* `0.00003201`\n' + '*Duration:* `1 day, 2:30:00 (1590.0 min)`' + ) # Reset singleton function to avoid random breaks telegram._rpc._fiat_converter.convert_amount = old_convamount diff --git a/tests/test_freqtradebot.py b/tests/test_freqtradebot.py index cfb9261e1..db05eddfc 100644 --- a/tests/test_freqtradebot.py +++ b/tests/test_freqtradebot.py @@ -1133,7 +1133,6 @@ def test_handle_stoploss_on_exchange(mocker, default_conf_usdt, fee, caplog, is_ trade.is_open = True trade.open_order_id = None trade.stoploss_order_id = "100" - trade.orders.append(Order( ft_order_side='stoploss', order_id='100', @@ -3277,7 +3276,7 @@ def test_execute_trade_exit_down(default_conf_usdt, ticker_usdt, fee, ticker_usd 'close_rate': ANY, 'sub_trade': False, 'stake_amount': pytest.approx(60), - } == last_msg + } == last_msg @pytest.mark.parametrize( diff --git a/tests/test_persistence.py b/tests/test_persistence.py index 406584100..832ea316b 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -2411,7 +2411,7 @@ def test_recalc_trade_from_orders(fee): assert pytest.approx(trade.fee_open_cost) == o1_fee_cost + o2_fee_cost + o3_fee_cost assert pytest.approx(trade.open_trade_value) == o1_trade_val + o2_trade_val + o3_trade_val - # Just to make sure non partial sell orders are ignored, let's calculate one more time. + # Just to make sure full sell orders are ignored, let's calculate one more time. sell1 = Order( ft_order_side='sell', @@ -2574,7 +2574,7 @@ def test_recalc_trade_from_orders_ignores_bad_orders(fee, is_short): assert trade.open_trade_value == 2 * o1_trade_val assert trade.nr_of_successful_entries == 2 - # Just to make sure non partial exit orders are ignored, let's calculate one more time. + # Reduce position - this will reduce amount again. sell1 = Order( ft_order_side=exit_side, ft_pair=trade.pair,