From 4ac223793748e6e92992df39e718a6b4b5363976 Mon Sep 17 00:00:00 2001 From: Sam Germain Date: Sat, 21 Aug 2021 16:26:04 -0600 Subject: [PATCH] Changed ftx set_leverage implementation --- freqtrade/exchange/binance.py | 16 ---------------- freqtrade/exchange/exchange.py | 13 ++++++++++--- freqtrade/exchange/ftx.py | 16 ---------------- 3 files changed, 10 insertions(+), 35 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index 4199f41ab..b243e9779 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -133,22 +133,6 @@ class Binance(Exchange): pair_brackets = self._leverage_brackets[pair] max_lev = 1.0 for [min_amount, margin_req] in pair_brackets: - print(nominal_value, min_amount) if nominal_value >= min_amount: max_lev = 1/margin_req return max_lev - - def set_leverage(self, pair, leverage): - """ - Binance Futures must set the leverage before making a futures trade, in order to not - have the same leverage on every trade - """ - 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/exchange.py b/freqtrade/exchange/exchange.py index 54db415c3..aae8eb08e 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -1542,13 +1542,20 @@ class Exchange: raise OperationalException( f"{self.name.capitalize()}.get_max_leverage has not been implemented.") - def set_leverage(self, pair, leverage): + def set_leverage(self, leverage: float, pair: Optional[str]): """ Set's the leverage before making a trade, in order to not have the same leverage on every trade """ - raise OperationalException( - f"{self.name.capitalize()}.set_leverage has not been implemented.") + 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 def is_exchange_known_ccxt(exchange_name: str, ccxt_module: CcxtModuleType = None) -> bool: diff --git a/freqtrade/exchange/ftx.py b/freqtrade/exchange/ftx.py index 8ffba92c7..9ed220806 100644 --- a/freqtrade/exchange/ftx.py +++ b/freqtrade/exchange/ftx.py @@ -175,19 +175,3 @@ class Ftx(Exchange): :nominal_value: Here for super method, not used on FTX """ return 20.0 - - def set_leverage(self, pair, leverage): - """ - Sets the leverage used for the user's account - :param pair: Here for super method, not used on FTX - :param 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