customized set_leverage for different exchanges

This commit is contained in:
Sam Germain
2021-09-12 02:42:13 -06:00
parent bc102d57c9
commit ad44048e29
5 changed files with 40 additions and 18 deletions

View File

@@ -153,17 +153,20 @@ class Binance(Exchange):
return max_lev
@retrier
def _set_leverage(self, leverage: float, pair: Optional[str]):
def _set_leverage(
self,
leverage: float,
pair: Optional[str],
trading_mode: Optional[TradingMode]
):
"""
Set's the leverage before making a trade, in order to not
have the same leverage on every trade
"""
if not self.exchange_has("setLeverage"):
# Some exchanges only support one collateral type
return
trading_mode = trading_mode or self.trading_mode
try:
if self.trading_mode == TradingMode.FUTURES:
if trading_mode == TradingMode.FUTURES:
self._api.set_leverage(symbol=pair, leverage=leverage)
except ccxt.DDoSProtection as e:
raise DDosProtection(e) from e

View File

@@ -778,7 +778,7 @@ class Exchange:
return dry_order
if self.trading_mode != TradingMode.SPOT:
self._set_leverage(pair, leverage)
self._set_leverage(leverage, pair)
params = self._params.copy()
if time_in_force != 'gtc' and ordertype != 'market':
param = self._ft_has.get('time_in_force_parameter', '')
@@ -1602,7 +1602,12 @@ class Exchange:
return 1.0
@retrier
def _set_leverage(self, leverage: float, pair: Optional[str]):
def _set_leverage(
self,
leverage: float,
pair: Optional[str],
trading_mode: Optional[TradingMode]
):
"""
Set's the leverage before making a trade, in order to not
have the same leverage on every trade

View File

@@ -172,9 +172,17 @@ class Kraken(Exchange):
"""
return float(max(self._leverage_brackets[pair]))
def _set_leverage(self, pair, leverage):
def _set_leverage(
self,
leverage: float,
pair: Optional[str],
trading_mode: Optional[TradingMode]
):
"""
Kraken set's the leverage as an option in the order object, so we need to
add it to params
"""
self._params['leverage'] = leverage
if leverage > 1.0:
self._params['leverage'] = leverage
else:
del self._params['leverage']