Added get_liquidation_price check

This commit is contained in:
Sam Germain 2022-01-14 07:16:00 -06:00
parent bb2b2211d0
commit c2f9201512
2 changed files with 34 additions and 3 deletions

View File

@ -1993,7 +1993,9 @@ class Exchange:
return
try:
return self._api.fetch_positions(pair).liquidationPrice
positions = self._api.fetch_positions([pair])
position = positions[0]
return position['liquidationPrice']
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e
except (ccxt.NetworkError, ccxt.ExchangeError) as e:

View File

@ -3583,10 +3583,39 @@ def test_calculate_funding_fees(
def test_get_liquidation_price(mocker, default_conf):
api_mock = MagicMock()
api_mock.fetch_positions = MagicMock()
type(api_mock).has = PropertyMock(return_value={'fetchPositions': True})
api_mock.fetch_positions = MagicMock(return_value=[{
'info': {},
'symbol': 'NEAR/USDT:USDT',
'timestamp': 1642164737148,
'datetime': '2022-01-14T12:52:17.148Z',
'initialMargin': 1.51072,
'initialMarginPercentage': 0.1,
'maintenanceMargin': 0.38916147,
'maintenanceMarginPercentage': 0.025,
'entryPrice': 18.884,
'notional': 15.1072,
'leverage': 9.97,
'unrealizedPnl': 0.0048,
'contracts': 8,
'contractSize': 0.1,
'marginRatio': None,
'liquidationPrice': 17.47,
'markPrice': 18.89,
'collateral': 1.52549075,
'marginType': 'isolated',
'side': 'buy',
'percentage': 0.003177292946409658
}])
mocker.patch.multiple(
'freqtrade.exchange.Exchange',
exchange_has=MagicMock(return_value=True),
)
default_conf['dry_run'] = False
exchange = get_patched_exchange(mocker, default_conf)
liq_price = exchange.get_liquidation_price('NEAR/USDT:USDT')
assert liq_price == 17.47
ccxt_exceptionhandlers(
mocker,
default_conf,