Changed ftx set_leverage implementation

This commit is contained in:
Sam Germain 2021-08-21 16:26:04 -06:00
parent f5fd8dcc05
commit 4ac2237937
3 changed files with 10 additions and 35 deletions

View File

@ -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

View File

@ -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:

View File

@ -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