get_maintenance_ratio_and_amt tests
This commit is contained in:
parent
60a45ff394
commit
4a1ed01708
@ -2272,7 +2272,7 @@ class Exchange:
|
|||||||
def get_maintenance_ratio_and_amt(
|
def get_maintenance_ratio_and_amt(
|
||||||
self,
|
self,
|
||||||
pair: str,
|
pair: str,
|
||||||
nominal_value: Optional[float] = 0.0,
|
nominal_value: float = 0.0,
|
||||||
) -> Tuple[float, Optional[float]]:
|
) -> Tuple[float, Optional[float]]:
|
||||||
"""
|
"""
|
||||||
:param pair: Market symbol
|
:param pair: Market symbol
|
||||||
@ -2280,10 +2280,6 @@ class Exchange:
|
|||||||
maintenance amount only on Binance
|
maintenance amount only on Binance
|
||||||
:return: (maintenance margin ratio, maintenance amount)
|
:return: (maintenance margin ratio, maintenance amount)
|
||||||
"""
|
"""
|
||||||
if nominal_value is None:
|
|
||||||
raise OperationalException(
|
|
||||||
f"nominal value is required for {self.name}.get_maintenance_ratio_and_amt"
|
|
||||||
)
|
|
||||||
|
|
||||||
if self._api.has['fetchLeverageTiers']:
|
if self._api.has['fetchLeverageTiers']:
|
||||||
if pair not in self._leverage_tiers:
|
if pair not in self._leverage_tiers:
|
||||||
|
@ -4350,10 +4350,47 @@ def test_get_leverage_tiers_for_pair(mocker, default_conf, leverage_tiers):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_get_maintenance_ratio_and_amt(mocker, default_conf, leverage_tiers):
|
def test_get_maintenance_ratio_and_amt_exceptions(mocker, default_conf, leverage_tiers):
|
||||||
# TODO-lev
|
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
default_conf['trading_mode'] = 'futures'
|
default_conf['trading_mode'] = 'futures'
|
||||||
default_conf['margin_mode'] = 'isolated'
|
default_conf['margin_mode'] = 'isolated'
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
assert exchange
|
pair = '1000SHIB/USDT'
|
||||||
|
|
||||||
|
exchange._leverage_tiers = {}
|
||||||
|
exchange.get_leverage_tiers_for_pair = MagicMock(return_value=[])
|
||||||
|
|
||||||
|
with pytest.raises(
|
||||||
|
InvalidOrderException,
|
||||||
|
match=f"Cannot calculate liquidation price for {pair}",
|
||||||
|
):
|
||||||
|
exchange.get_maintenance_ratio_and_amt(pair, 10000)
|
||||||
|
|
||||||
|
exchange._leverage_tiers = leverage_tiers
|
||||||
|
with pytest.raises(
|
||||||
|
OperationalException,
|
||||||
|
match='nominal value can not be lower than 0',
|
||||||
|
):
|
||||||
|
exchange.get_maintenance_ratio_and_amt(pair, -1)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('pair,value,mmr,maintAmt', [
|
||||||
|
('ADA/BUSD', 500, 0.025, 0.0),
|
||||||
|
('ADA/BUSD', 20000000, 0.5, 1527500.0),
|
||||||
|
('ZEC/USDT', 500, 0.01, 0.0),
|
||||||
|
('ZEC/USDT', 20000000, 0.5, 654500.0),
|
||||||
|
])
|
||||||
|
def test_get_maintenance_ratio_and_amt(
|
||||||
|
mocker,
|
||||||
|
default_conf,
|
||||||
|
leverage_tiers,
|
||||||
|
pair,
|
||||||
|
value,
|
||||||
|
mmr,
|
||||||
|
maintAmt
|
||||||
|
):
|
||||||
|
api_mock = MagicMock()
|
||||||
|
default_conf['trading_mode'] = 'futures'
|
||||||
|
default_conf['margin_mode'] = 'isolated'
|
||||||
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
|
exchange.get_maintenance_ratio_and_amt(pair, value) == (mmr, maintAmt)
|
||||||
|
Loading…
Reference in New Issue
Block a user