fixed test_load_leverage_tiers
This commit is contained in:
parent
183f85efe3
commit
c70050e750
@ -248,19 +248,22 @@ class Binance(Exchange):
|
|||||||
|
|
||||||
@retrier
|
@retrier
|
||||||
def load_leverage_tiers(self) -> Dict[str, List[Dict]]:
|
def load_leverage_tiers(self) -> Dict[str, List[Dict]]:
|
||||||
if self._config['dry_run']:
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
leverage_tiers_path = (
|
if self._config['dry_run']:
|
||||||
Path(__file__).parent / 'binance_leverage_tiers.json'
|
leverage_tiers_path = (
|
||||||
)
|
Path(__file__).parent / 'binance_leverage_tiers.json'
|
||||||
with open(leverage_tiers_path) as json_file:
|
)
|
||||||
return json.load(json_file)
|
with open(leverage_tiers_path) as json_file:
|
||||||
|
return json.load(json_file)
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
return self._api.fetch_leverage_tiers()
|
||||||
|
except ccxt.DDoSProtection as e:
|
||||||
|
raise DDosProtection(e) from e
|
||||||
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
|
raise TemporaryError(f'Could not fetch leverage amounts due to'
|
||||||
|
f'{e.__class__.__name__}. Message: {e}') from e
|
||||||
|
except ccxt.BaseError as e:
|
||||||
|
raise OperationalException(e) from e
|
||||||
else:
|
else:
|
||||||
try:
|
return {}
|
||||||
return self._api.fetch_leverage_tiers()
|
|
||||||
except ccxt.DDoSProtection as e:
|
|
||||||
raise DDosProtection(e) from e
|
|
||||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
|
||||||
raise TemporaryError(f'Could not fetch leverage amounts due to'
|
|
||||||
f'{e.__class__.__name__}. Message: {e}') from e
|
|
||||||
except ccxt.BaseError as e:
|
|
||||||
raise OperationalException(e) from e
|
|
||||||
|
@ -4236,54 +4236,54 @@ def test_get_max_pair_stake_amount(
|
|||||||
assert exchange.get_max_pair_stake_amount('ADA/USDT', 2.0) == 500
|
assert exchange.get_max_pair_stake_amount('ADA/USDT', 2.0) == 500
|
||||||
|
|
||||||
|
|
||||||
def test_load_leverage_tiers(mocker, default_conf, leverage_tiers):
|
@pytest.mark.parametrize('exchange_name', EXCHANGES)
|
||||||
|
def test_load_leverage_tiers(mocker, default_conf, leverage_tiers, exchange_name):
|
||||||
api_mock = MagicMock()
|
api_mock = MagicMock()
|
||||||
api_mock.fetch_leverage_tiers = MagicMock()
|
api_mock.fetch_leverage_tiers = MagicMock()
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchLeverageTiers': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchLeverageTiers': True})
|
||||||
default_conf['dry_run'] = False
|
default_conf['dry_run'] = False
|
||||||
|
mocker.patch('freqtrade.exchange.exchange.Exchange.validate_trading_mode_and_margin_mode')
|
||||||
|
|
||||||
api_mock.fetch_leverage_tiers = MagicMock(return_value=[
|
api_mock.fetch_leverage_tiers = MagicMock(return_value={
|
||||||
{
|
'ADA/USDT:USDT': [
|
||||||
'ADA/USDT:USDT': [
|
{
|
||||||
{
|
'tier': 1,
|
||||||
'tier': 1,
|
'notionalFloor': 0,
|
||||||
'notionalFloor': 0,
|
'notionalCap': 500,
|
||||||
'notionalCap': 500,
|
'maintenanceMarginRatio': 0.02,
|
||||||
'maintenanceMarginRatio': 0.02,
|
'maxLeverage': 75,
|
||||||
'maxLeverage': 75,
|
'info': {
|
||||||
'info': {
|
'baseMaxLoan': '',
|
||||||
'baseMaxLoan': '',
|
'imr': '0.013',
|
||||||
'imr': '0.013',
|
'instId': '',
|
||||||
'instId': '',
|
'maxLever': '75',
|
||||||
'maxLever': '75',
|
'maxSz': '500',
|
||||||
'maxSz': '500',
|
'minSz': '0',
|
||||||
'minSz': '0',
|
'mmr': '0.01',
|
||||||
'mmr': '0.01',
|
'optMgnFactor': '0',
|
||||||
'optMgnFactor': '0',
|
'quoteMaxLoan': '',
|
||||||
'quoteMaxLoan': '',
|
'tier': '1',
|
||||||
'tier': '1',
|
'uly': 'ADA-USDT'
|
||||||
'uly': 'ADA-USDT'
|
}
|
||||||
}
|
},
|
||||||
},
|
]
|
||||||
]
|
})
|
||||||
}
|
|
||||||
])
|
|
||||||
|
|
||||||
# SPOT
|
# SPOT
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
assert exchange.load_leverage_tiers() == {}
|
assert exchange.load_leverage_tiers() == {}
|
||||||
|
|
||||||
# FUTURES has.fetchLeverageTiers == False
|
# FUTURES has.fetchLeverageTiers == False
|
||||||
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, id=exchange_name)
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchLeverageTiers': False})
|
type(api_mock).has = PropertyMock(return_value={'fetchLeverageTiers': False})
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
||||||
assert exchange.load_leverage_tiers() == {}
|
assert exchange.load_leverage_tiers() == {}
|
||||||
|
|
||||||
# FUTURES regular
|
# FUTURES regular
|
||||||
type(api_mock).has = PropertyMock(return_value={'fetchLeverageTiers': True})
|
type(api_mock).has = PropertyMock(return_value={'fetchLeverageTiers': True})
|
||||||
exchange = get_patched_exchange(mocker, default_conf, api_mock)
|
exchange = get_patched_exchange(mocker, default_conf, api_mock, id=exchange_name)
|
||||||
assert exchange.load_leverage_tiers() == {
|
assert exchange.load_leverage_tiers() == {
|
||||||
'ADA/USDT:USDT': [
|
'ADA/USDT:USDT': [
|
||||||
{
|
{
|
||||||
@ -4313,7 +4313,7 @@ def test_load_leverage_tiers(mocker, default_conf, leverage_tiers):
|
|||||||
mocker,
|
mocker,
|
||||||
default_conf,
|
default_conf,
|
||||||
api_mock,
|
api_mock,
|
||||||
"ftx",
|
exchange_name,
|
||||||
"load_leverage_tiers",
|
"load_leverage_tiers",
|
||||||
"fetch_leverage_tiers",
|
"fetch_leverage_tiers",
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user