fixed test_load_leverage_tiers

This commit is contained in:
Sam Germain 2022-02-16 05:26:52 -06:00
parent 183f85efe3
commit c70050e750
2 changed files with 49 additions and 46 deletions

View File

@ -248,6 +248,7 @@ 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.trading_mode == TradingMode.FUTURES:
if self._config['dry_run']: if self._config['dry_run']:
leverage_tiers_path = ( leverage_tiers_path = (
Path(__file__).parent / 'binance_leverage_tiers.json' Path(__file__).parent / 'binance_leverage_tiers.json'
@ -264,3 +265,5 @@ class Binance(Exchange):
f'{e.__class__.__name__}. Message: {e}') from e f'{e.__class__.__name__}. Message: {e}') from e
except ccxt.BaseError as e: except ccxt.BaseError as e:
raise OperationalException(e) from e raise OperationalException(e) from e
else:
return {}

View File

@ -4236,14 +4236,15 @@ 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,
@ -4266,24 +4267,23 @@ def test_load_leverage_tiers(mocker, default_conf, leverage_tiers):
} }
}, },
] ]
} })
])
# 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",
) )