From 9de63412c19ce1155125f53b47e0a485f60ffacc Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Mon, 31 Jan 2022 13:49:06 -0600 Subject: [PATCH] exchange.get_liquidation_price arguments are not optional --- freqtrade/exchange/exchange.py | 18 ++++----------- tests/exchange/test_exchange.py | 41 ++++++++++++++++++++------------- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index c25a975e6..3ba791861 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1987,10 +1987,10 @@ class Exchange: self, pair: str, # Dry-run - open_rate: Optional[float] = None, # Entry price of position - is_short: Optional[bool] = None, - position: Optional[float] = None, # Absolute value of position size - wallet_balance: Optional[float] = None, # Or margin balance + open_rate: float, # Entry price of position + is_short: bool, + position: float, # Absolute value of position size + wallet_balance: float, # Or margin balance mm_ex_1: float = 0.0, # (Binance) Cross only upnl_ex_1: float = 0.0, # (Binance) Cross only ): @@ -2007,16 +2007,6 @@ class Exchange: f"{self.name} does not support {self.collateral.value} {self.trading_mode.value}") if self._config['dry_run'] or not self.exchange_has("fetchPositions"): - if ( - open_rate is None or - is_short is None or - position is None or - wallet_balance is None - ): - raise OperationalException( - f"Parameters open_rate, is_short, position, wallet_balance are" - f"required by {self.name}.liquidation_price for dry_run" - ) return self.dry_run_liquidation_price( pair=pair, diff --git a/tests/exchange/test_exchange.py b/tests/exchange/test_exchange.py index aaeada8e2..ba96e45f3 100644 --- a/tests/exchange/test_exchange.py +++ b/tests/exchange/test_exchange.py @@ -3631,7 +3631,13 @@ def test_get_liquidation_price(mocker, default_conf): default_conf['collateral'] = 'isolated' exchange = get_patched_exchange(mocker, default_conf, api_mock) - liq_price = exchange.get_liquidation_price('NEAR/USDT:USDT') + liq_price = exchange.get_liquidation_price( + pair='NEAR/USDT:USDT', + open_rate=0.0, + is_short=False, + position=0.0, + wallet_balance=0.0, + ) assert liq_price == 17.47 ccxt_exceptionhandlers( @@ -3641,7 +3647,11 @@ def test_get_liquidation_price(mocker, default_conf): "binance", "get_liquidation_price", "fetch_positions", - pair="XRP/USDT" + pair="XRP/USDT", + open_rate=0.0, + is_short=False, + position=0.0, + wallet_balance=0.0, ) @@ -3974,15 +3984,15 @@ def test__amount_to_contracts( assert result_amount == param_amount -@pytest.mark.parametrize('exchange_name,open_rate,is_short,leverage,trading_mode,collateral', [ +@pytest.mark.parametrize('exchange_name,open_rate,is_short,trading_mode,collateral', [ # Bittrex - ('bittrex', 2.0, False, 3.0, 'spot', None), - ('bittrex', 2.0, False, 1.0, 'spot', 'cross'), - ('bittrex', 2.0, True, 3.0, 'spot', 'isolated'), + ('bittrex', 2.0, False, 'spot', None), + ('bittrex', 2.0, False, 'spot', 'cross'), + ('bittrex', 2.0, True, 'spot', 'isolated'), # Binance - ('binance', 2.0, False, 3.0, 'spot', None), - ('binance', 2.0, False, 1.0, 'spot', 'cross'), - ('binance', 2.0, True, 3.0, 'spot', 'isolated'), + ('binance', 2.0, False, 'spot', None), + ('binance', 2.0, False, 'spot', 'cross'), + ('binance', 2.0, True, 'spot', 'isolated'), ]) def test_liquidation_price_is_none( mocker, @@ -3990,7 +4000,6 @@ def test_liquidation_price_is_none( exchange_name, open_rate, is_short, - leverage, trading_mode, collateral ): @@ -4009,21 +4018,21 @@ def test_liquidation_price_is_none( @pytest.mark.parametrize( - 'exchange_name, is_short, leverage, trading_mode, collateral, wallet_balance, ' + 'exchange_name, is_short, trading_mode, collateral, wallet_balance, ' 'mm_ex_1, upnl_ex_1, maintenance_amt, position, open_rate, ' 'mm_ratio, expected', [ - ("binance", False, 1, 'futures', 'isolated', 1535443.01, 0.0, + ("binance", False, 'futures', 'isolated', 1535443.01, 0.0, 0.0, 135365.00, 3683.979, 1456.84, 0.10, 1114.78), - ("binance", False, 1, 'futures', 'isolated', 1535443.01, 0.0, + ("binance", False, 'futures', 'isolated', 1535443.01, 0.0, 0.0, 16300.000, 109.488, 32481.980, 0.025, 18778.73), - ("binance", False, 1, 'futures', 'cross', 1535443.01, 71200.81144, + ("binance", False, 'futures', 'cross', 1535443.01, 71200.81144, -56354.57, 135365.00, 3683.979, 1456.84, 0.10, 1153.26), - ("binance", False, 1, 'futures', 'cross', 1535443.01, 356512.508, + ("binance", False, 'futures', 'cross', 1535443.01, 356512.508, -448192.89, 16300.000, 109.488, 32481.980, 0.025, 26316.89) ]) def test_liquidation_price( - mocker, default_conf, exchange_name, open_rate, is_short, leverage, trading_mode, + mocker, default_conf, exchange_name, open_rate, is_short, trading_mode, collateral, wallet_balance, mm_ex_1, upnl_ex_1, maintenance_amt, position, mm_ratio, expected ): default_conf['trading_mode'] = trading_mode