Fixed failing test_execute_trade_exit_market_order

This commit is contained in:
Sam Germain 2021-10-14 04:45:48 -06:00
parent 2dc402fbf7
commit 0afd76c183

View File

@ -3225,9 +3225,33 @@ def test_may_execute_trade_exit_after_stoploss_on_exchange_hit(default_conf_usdt
assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.SELL assert rpc_mock.call_args_list[2][0][0]['type'] == RPCMessageType.SELL
@ pytest.mark.parametrize("is_short", [False, True]) @pytest.mark.parametrize(
def test_execute_trade_exit_market_order(default_conf_usdt, ticker_usdt, fee, is_short, "is_short,amount,open_rate,current_rate,limit,profit_amount,profit_ratio,profit_or_loss", [
ticker_usdt_sell_up, mocker) -> None: (False, 30, 2.0, 2.3, 2.2, 5.685, 0.09451372, 'profit'),
# TODO-lev: Should the current rate be 2.2 for shorts?
(True, 29.70297029, 2.02, 2.2, 2.3, -8.63762376, -0.1443212, 'loss'),
])
def test_execute_trade_exit_market_order(
default_conf_usdt, ticker_usdt, fee, is_short, current_rate, amount, open_rate,
limit, profit_amount, profit_ratio, profit_or_loss, ticker_usdt_sell_up, mocker
) -> None:
"""
amount
long: 60 / 2.0 = 30
short: 60 / 2.02 = 29.70297029
open_value
long: (30 * 2.0) + (30 * 2.0 * 0.0025) = 60.15
short: (29.702970297029704 * 2.02) - (29.702970297029704 * 2.02 * 0.0025) = 59.85
close_value
long: (30 * 2.2) - (30 * 2.2 * 0.0025) = 65.835
short: (29.702970297029704 * 2.3) + (29.702970297029704 * 2.3 * 0.0025) = 68.48762376237624
profit
long: 65.835 - 60.15 = 5.684999999999995
short: 59.85 - 68.48762376237624 = -8.637623762376244
profit_ratio
long: (65.835/60.15) - 1 = 0.0945137157107232
short: 1 - (68.48762376237624/59.85) = -0.1443211990371971
"""
rpc_mock = patch_RPCManager(mocker) rpc_mock = patch_RPCManager(mocker)
patch_exchange(mocker) patch_exchange(mocker)
mocker.patch.multiple( mocker.patch.multiple(
@ -3262,7 +3286,7 @@ def test_execute_trade_exit_market_order(default_conf_usdt, ticker_usdt, fee, is
) )
assert not trade.is_open assert not trade.is_open
assert trade.close_profit == 0.09451372 assert trade.close_profit == profit_ratio
assert rpc_mock.call_count == 3 assert rpc_mock.call_count == 3
last_msg = rpc_mock.call_args_list[-1][0][0] last_msg = rpc_mock.call_args_list[-1][0][0]
@ -3271,14 +3295,14 @@ def test_execute_trade_exit_market_order(default_conf_usdt, ticker_usdt, fee, is
'trade_id': 1, 'trade_id': 1,
'exchange': 'Binance', 'exchange': 'Binance',
'pair': 'ETH/USDT', 'pair': 'ETH/USDT',
'gain': 'profit', 'gain': profit_or_loss,
'limit': 2.2, 'limit': limit,
'amount': 30.0, 'amount': round(amount, 9),
'order_type': 'market', 'order_type': 'market',
'open_rate': 2.0, 'open_rate': open_rate,
'current_rate': 2.3, 'current_rate': current_rate,
'profit_amount': 5.685, 'profit_amount': profit_amount,
'profit_ratio': 0.09451372, 'profit_ratio': profit_ratio,
'stake_currency': 'USDT', 'stake_currency': 'USDT',
'fiat_currency': 'USD', 'fiat_currency': 'USD',
'sell_reason': SellType.ROI.value, 'sell_reason': SellType.ROI.value,