Added get_liquidation_price check
This commit is contained in:
parent
bb2b2211d0
commit
c2f9201512
@ -1993,7 +1993,9 @@ class Exchange:
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
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:
|
except ccxt.DDoSProtection as e:
|
||||||
raise DDosProtection(e) from e
|
raise DDosProtection(e) from e
|
||||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
|
@ -3583,10 +3583,39 @@ def test_calculate_funding_fees(
|
|||||||
def test_get_liquidation_price(mocker, default_conf):
|
def test_get_liquidation_price(mocker, default_conf):
|
||||||
|
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.fetch_positions = MagicMock()
|
api_mock.fetch_positions = MagicMock(return_value=[{
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchPositions': True})
|
'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
|
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(
|
ccxt_exceptionhandlers(
|
||||||
mocker,
|
mocker,
|
||||||
default_conf,
|
default_conf,
|
||||||
|
Loading…
Reference in New Issue
Block a user