Revert "moved get_max_leverage to get_min_pair_stake_amount"

This reverts commit 90e48d5b98bcfb1452aa818a3274745eac395712.
This commit is contained in:
Sam Germain 2022-01-31 02:31:44 -06:00
parent 73319a74d3
commit 64ad810445
2 changed files with 95 additions and 27 deletions

View File

@ -684,27 +684,27 @@ class Exchange:
except KeyError: except KeyError:
raise ValueError(f"Can't get market information for symbol {pair}") raise ValueError(f"Can't get market information for symbol {pair}")
if 'limits' not in market:
return None
min_stake_amounts = [] min_stake_amounts = []
max_stake_amounts = [float('inf')]
limits = market['limits'] limits = market['limits']
if (limits['cost']['min'] is not None): if ('cost' in limits and 'min' in limits['cost']
and limits['cost']['min'] is not None):
min_stake_amounts.append( min_stake_amounts.append(
self._contracts_to_amount(pair, limits['cost']['min']) self._contracts_to_amount(
pair,
limits['cost']['min']
)
) )
if (limits['amount']['min'] is not None): if ('amount' in limits and 'min' in limits['amount']
and limits['amount']['min'] is not None):
min_stake_amounts.append( min_stake_amounts.append(
self._contracts_to_amount(pair, limits['amount']['min'] * price) self._contracts_to_amount(
pair,
limits['amount']['min'] * price
) )
if (limits['cost']['max'] is not None):
max_stake_amounts.append(
self._contracts_to_amount(pair, limits['cost']['max'])
)
if (limits['amount']['max'] is not None):
max_stake_amounts.append(
self._contracts_to_amount(pair, limits['amount']['max'] * price)
) )
if not min_stake_amounts: if not min_stake_amounts:
@ -722,12 +722,9 @@ class Exchange:
# The value returned should satisfy both limits: for amount (base currency) and # The value returned should satisfy both limits: for amount (base currency) and
# for cost (quote, stake currency), so max() is used here. # for cost (quote, stake currency), so max() is used here.
# See also #2575 at github. # See also #2575 at github.
return min( return self._get_stake_amount_considering_leverage(
self._get_stake_amount_considering_leverage(
max(min_stake_amounts) * amount_reserve_percent, max(min_stake_amounts) * amount_reserve_percent,
leverage or 1.0 leverage or 1.0
),
min(max_stake_amounts)
) )
def _get_stake_amount_considering_leverage(self, stake_amount: float, leverage: float): def _get_stake_amount_considering_leverage(self, stake_amount: float, leverage: float):

View File

@ -4050,18 +4050,35 @@ def test_get_max_amount_tradable(
): ):
api_mock = MagicMock() api_mock = MagicMock()
exchange = get_patched_exchange(mocker, default_conf, api_mock) exchange = get_patched_exchange(mocker, default_conf, api_mock)
# TODO-lev: Move this to test_get_min_pair_stake_amount
markets = { markets = {
'XRP/USDT': { 'XRP/USDT': {
'limits': { 'limits': {
'leverage': {
'min': None,
'max': None,
},
'amount': { 'amount': {
'min': 0.001, 'min': 0.001,
'max': 10000 'max': 10000
}, },
'price': {
'min': 39.86,
'max': 306177
},
'cost': { 'cost': {
'min': 5, 'min': 5,
'max': None 'max': None
}, },
'market': {
'min': 0.001,
'max': 2000
},
},
'precision': {
'price': 2,
'amount': 3,
'base': 8,
'quote': 8
}, },
'contractSize': None, 'contractSize': None,
'spot': False, 'spot': False,
@ -4069,14 +4086,32 @@ def test_get_max_amount_tradable(
}, },
'LTC/USDT': { 'LTC/USDT': {
'limits': { 'limits': {
'leverage': {
'min': None,
'max': None,
},
'amount': { 'amount': {
'min': 0.001, 'min': 0.001,
'max': None 'max': None
}, },
'price': {
'min': 39.86,
'max': 306177
},
'cost': { 'cost': {
'min': 5, 'min': 5,
'max': None 'max': None
}, },
'market': {
'min': 0.001,
'max': 2000
},
},
'precision': {
'price': 2,
'amount': 3,
'base': 8,
'quote': 8
}, },
'contractSize': 0.01, 'contractSize': 0.01,
'spot': False, 'spot': False,
@ -4084,14 +4119,32 @@ def test_get_max_amount_tradable(
}, },
'ETH/USDT': { 'ETH/USDT': {
'limits': { 'limits': {
'leverage': {
'min': None,
'max': None,
},
'amount': { 'amount': {
'min': 0.001, 'min': 0.001,
'max': 10000 'max': 10000
}, },
'price': {
'min': 39.86,
'max': 306177
},
'cost': { 'cost': {
'min': 5, 'min': 5,
'max': None 'max': None
}, },
'market': {
'min': 0.001,
'max': 2000
},
},
'precision': {
'price': 2,
'amount': 3,
'base': 8,
'quote': 8
}, },
'contractSize': 0.01, 'contractSize': 0.01,
'spot': False, 'spot': False,
@ -4099,22 +4152,40 @@ def test_get_max_amount_tradable(
}, },
'BTC/USDT': { 'BTC/USDT': {
'limits': { 'limits': {
'leverage': {
'min': None,
'max': None,
},
'amount': { 'amount': {
'min': 0.001, 'min': 0.001,
'max': 10000 'max': 10000
}, },
'price': {
'min': 39.86,
'max': 306177
},
'cost': { 'cost': {
'min': 5, 'min': 5,
'max': None 'max': None
}, },
'market': {
'min': 0.001,
'max': 2000
},
},
'precision': {
'price': 2,
'amount': 3,
'base': 8,
'quote': 8
}, },
'contractSize': 0.01, 'contractSize': 0.01,
'spot': True, 'spot': True,
'swap': False 'swap': False
} }
} }
# mocker.patch('freqtrade.exchange.Exchange.markets', markets) mocker.patch('freqtrade.exchange.Exchange.markets', markets)
# assert exchange.get_max_amount_tradable('XRP/USDT') == 10000 assert exchange.get_max_amount_tradable('XRP/USDT') == 10000
# assert exchange.get_max_amount_tradable('LTC/USDT') == float('inf') assert exchange.get_max_amount_tradable('LTC/USDT') == float('inf')
# assert exchange.get_max_amount_tradable('ETH/USDT') == 100 assert exchange.get_max_amount_tradable('ETH/USDT') == 100
# assert exchange.get_max_amount_tradable('BTC/USDT') == 10000 assert exchange.get_max_amount_tradable('BTC/USDT') == 10000