Simplify liquidation price structure, improve test cov
This commit is contained in:
parent
226fa5d93c
commit
27a9f98d5f
@ -2611,8 +2611,9 @@ class Exchange:
|
|||||||
return None
|
return None
|
||||||
elif (self.trading_mode != TradingMode.FUTURES):
|
elif (self.trading_mode != TradingMode.FUTURES):
|
||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f"{self.name} does not support {self.margin_mode.value} {self.trading_mode.value}")
|
f"{self.name} does not support {self.margin_mode} {self.trading_mode}")
|
||||||
|
|
||||||
|
isolated_liq = None
|
||||||
if self._config['dry_run'] or not self.exchange_has("fetchPositions"):
|
if self._config['dry_run'] or not self.exchange_has("fetchPositions"):
|
||||||
|
|
||||||
isolated_liq = self.dry_run_liquidation_price(
|
isolated_liq = self.dry_run_liquidation_price(
|
||||||
@ -2630,8 +2631,6 @@ class Exchange:
|
|||||||
if len(positions) > 0:
|
if len(positions) > 0:
|
||||||
pos = positions[0]
|
pos = positions[0]
|
||||||
isolated_liq = pos['liquidationPrice']
|
isolated_liq = pos['liquidationPrice']
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
if isolated_liq:
|
if isolated_liq:
|
||||||
buffer_amount = abs(open_rate - isolated_liq) * self.liquidation_buffer
|
buffer_amount = abs(open_rate - isolated_liq) * self.liquidation_buffer
|
||||||
|
@ -5000,6 +5000,28 @@ def test_get_liquidation_price1(mocker, default_conf):
|
|||||||
)
|
)
|
||||||
assert liq_price == 17.540699999999998
|
assert liq_price == 17.540699999999998
|
||||||
|
|
||||||
|
api_mock.fetch_positions = MagicMock(return_value=[])
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
|
liq_price = exchange.get_liquidation_price(
|
||||||
|
pair='NEAR/USDT:USDT',
|
||||||
|
open_rate=18.884,
|
||||||
|
is_short=False,
|
||||||
|
amount=0.8,
|
||||||
|
stake_amount=18.884 * 0.8,
|
||||||
|
)
|
||||||
|
assert liq_price is None
|
||||||
|
default_conf['trading_mode'] = 'margin'
|
||||||
|
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
|
with pytest.raises(OperationalException, match=r'.*does not support .* margin'):
|
||||||
|
exchange.get_liquidation_price(
|
||||||
|
pair='NEAR/USDT:USDT',
|
||||||
|
open_rate=18.884,
|
||||||
|
is_short=False,
|
||||||
|
amount=0.8,
|
||||||
|
stake_amount=18.884 * 0.8,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('liquidation_buffer', [0.0, 0.05])
|
@pytest.mark.parametrize('liquidation_buffer', [0.0, 0.05])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
Reference in New Issue
Block a user