test_fill_leverage_brackets_kraken and test_get_max_leverage_binance now pass but test_fill_leverage_brackets_ftx does not if called after test_get_max_leverage_binance

This commit is contained in:
Sam Germain
2021-09-05 22:27:14 -06:00
parent 9e73d02663
commit 93da13212c
8 changed files with 103 additions and 310 deletions

View File

@@ -111,6 +111,7 @@ class Binance(Exchange):
def _apply_leverage_to_stake_amount(self, stake_amount: float, leverage: float):
return stake_amount / leverage
@retrier
def fill_leverage_brackets(self):
"""
Assigns property _leverage_brackets to a dictionary of information about the leverage
@@ -118,8 +119,8 @@ class Binance(Exchange):
"""
try:
leverage_brackets = self._api.load_leverage_brackets()
for pair, brackets in leverage_brackets.items:
self.leverage_brackets[pair] = [
for pair, brackets in leverage_brackets.items():
self._leverage_brackets[pair] = [
[
min_amount,
float(margin_req)

View File

@@ -158,13 +158,7 @@ class Exchange:
)
if trading_mode != TradingMode.SPOT:
try:
# TODO-lev: This shouldn't need to happen, but for some reason I get that the
# TODO-lev: method isn't implemented
self.fill_leverage_brackets()
except Exception as error:
logger.debug(error)
logger.debug("Could not load leverage_brackets")
self.fill_leverage_brackets()
logger.info('Using Exchange "%s"', self.name)

View File

@@ -141,30 +141,24 @@ class Kraken(Exchange):
allowed on each pair
"""
leverages = {}
try:
for pair, market in self.markets.items():
info = market['info']
leverage_buy = info['leverage_buy']
leverage_sell = info['leverage_sell']
if len(info['leverage_buy']) > 0 or len(info['leverage_sell']) > 0:
if leverage_buy != leverage_sell:
logger.warning(f"The buy leverage != the sell leverage for {pair}. Please"
"let freqtrade know because this has never happened before"
)
if max(leverage_buy) < max(leverage_sell):
leverages[pair] = leverage_buy
else:
leverages[pair] = leverage_sell
else:
for pair, market in self.markets.items():
info = market['info']
leverage_buy = info['leverage_buy'] if 'leverage_buy' in info else []
leverage_sell = info['leverage_sell'] if 'leverage_sell' in info else []
if len(leverage_buy) > 0 or len(leverage_sell) > 0:
if leverage_buy != leverage_sell:
logger.warning(
f"The buy({leverage_buy}) and sell({leverage_sell}) leverage are not equal"
"{pair}. Please let freqtrade know because this has never happened before"
)
if max(leverage_buy) < max(leverage_sell):
leverages[pair] = leverage_buy
self._leverage_brackets = leverages
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:
leverages[pair] = leverage_sell
else:
leverages[pair] = leverage_buy
self._leverage_brackets = leverages
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
"""
@@ -176,7 +170,7 @@ class Kraken(Exchange):
def set_leverage(self, pair, leverage):
"""
Kraken set's the leverage as an option it the order object, so it doesn't do
Kraken set's the leverage as an option in the order object, so it doesn't do
anything in this function
"""
return