Changed ftx set_leverage implementation
This commit is contained in:
parent
f5fd8dcc05
commit
4ac2237937
@ -133,22 +133,6 @@ class Binance(Exchange):
|
|||||||
pair_brackets = self._leverage_brackets[pair]
|
pair_brackets = self._leverage_brackets[pair]
|
||||||
max_lev = 1.0
|
max_lev = 1.0
|
||||||
for [min_amount, margin_req] in pair_brackets:
|
for [min_amount, margin_req] in pair_brackets:
|
||||||
print(nominal_value, min_amount)
|
|
||||||
if nominal_value >= min_amount:
|
if nominal_value >= min_amount:
|
||||||
max_lev = 1/margin_req
|
max_lev = 1/margin_req
|
||||||
return max_lev
|
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
|
|
||||||
|
@ -1542,13 +1542,20 @@ class Exchange:
|
|||||||
raise OperationalException(
|
raise OperationalException(
|
||||||
f"{self.name.capitalize()}.get_max_leverage has not been implemented.")
|
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
|
Set's the leverage before making a trade, in order to not
|
||||||
have the same leverage on every trade
|
have the same leverage on every trade
|
||||||
"""
|
"""
|
||||||
raise OperationalException(
|
try:
|
||||||
f"{self.name.capitalize()}.set_leverage has not been implemented.")
|
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:
|
def is_exchange_known_ccxt(exchange_name: str, ccxt_module: CcxtModuleType = None) -> bool:
|
||||||
|
@ -175,19 +175,3 @@ class Ftx(Exchange):
|
|||||||
:nominal_value: Here for super method, not used on FTX
|
:nominal_value: Here for super method, not used on FTX
|
||||||
"""
|
"""
|
||||||
return 20.0
|
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
|
|
||||||
|
Loading…
Reference in New Issue
Block a user