diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index 1339677d2..15599eff9 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -104,17 +104,26 @@ class Binance(Exchange): Assigns property _leverage_brackets to a dictionary of information about the leverage allowed on each pair """ - leverage_brackets = self._api.load_leverage_brackets() - for pair, brackets in leverage_brackets.items: - self.leverage_brackets[pair] = [ - [ - min_amount, - float(margin_req) - ] for [ - min_amount, - margin_req - ] in brackets - ] + try: + leverage_brackets = self._api.load_leverage_brackets() + for pair, brackets in leverage_brackets.items: + self.leverage_brackets[pair] = [ + [ + min_amount, + float(margin_req) + ] for [ + min_amount, + margin_req + ] in brackets + ] + + 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 def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float: """ @@ -135,4 +144,12 @@ class Binance(Exchange): Binance Futures must set the leverage before making a futures trade, in order to not have the same leverage on every trade """ - self._api.set_leverage(symbol=pair, leverage=leverage) + try: + self._api.set_leverage(symbol=pair, leverage=leverage) + except ccxt.DDoSProtection as e: + raise DDosProtection(e) from e + except (ccxt.NetworkError, ccxt.ExchangeError) as e: + raise TemporaryError( + f'Could not set leverage due to {e.__class__.__name__}. Message: {e}') from e + except ccxt.BaseError as e: + raise OperationalException(e) from e diff --git a/freqtrade/exchange/ftx.py b/freqtrade/exchange/ftx.py index 64e728761..8ffba92c7 100644 --- a/freqtrade/exchange/ftx.py +++ b/freqtrade/exchange/ftx.py @@ -182,4 +182,12 @@ class Ftx(Exchange): :param pair: Here for super method, not used on FTX :param leverage: """ - self._api.private_post_account_leverage({'leverage': leverage}) + try: + self._api.private_post_account_leverage({'leverage': leverage}) + 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 diff --git a/freqtrade/exchange/kraken.py b/freqtrade/exchange/kraken.py index 358a1991c..e020f7fd8 100644 --- a/freqtrade/exchange/kraken.py +++ b/freqtrade/exchange/kraken.py @@ -135,22 +135,30 @@ class Kraken(Exchange): """ # TODO-lev: Not sure if this works correctly for futures leverages = {} - for pair, market in self._api.load_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: - print(f"\033[91m 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 + try: + for pair, market in self._api.load_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: - leverages[pair] = leverage_sell - else: - leverages[pair] = leverage_buy - self._leverage_brackets = leverages + 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 def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float: """