okex._lev_prep, removing rounding from default set_leverage

This commit is contained in:
Sam Germain 2022-02-02 00:28:57 -06:00
parent 8e51360f75
commit a741356d65
4 changed files with 30 additions and 6 deletions

View File

@ -93,7 +93,7 @@ class Binance(Exchange):
rate = self.price_to_precision(pair, rate)
self._lev_prep(pair, leverage)
self._lev_prep(pair, leverage, side)
order = self._api.create_order(
symbol=pair,
type=ordertype,

View File

@ -877,7 +877,12 @@ class Exchange:
# Order handling
def _lev_prep(self, pair: str, leverage: float):
def _lev_prep(
self,
pair: str,
leverage: float,
side: str # buy or sell
):
if self.trading_mode != TradingMode.SPOT:
self.set_margin_mode(pair, self.margin_mode)
self._set_leverage(leverage, pair)
@ -923,7 +928,7 @@ class Exchange:
rate_for_order = self.price_to_precision(pair, rate) if needs_price else None
if not reduceOnly:
self._lev_prep(pair, leverage)
self._lev_prep(pair, leverage, side)
order = self._api.create_order(
pair,
@ -1853,7 +1858,7 @@ class Exchange:
return
try:
self._api.set_leverage(symbol=pair, leverage=round(leverage))
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:

View File

@ -76,7 +76,7 @@ class Ftx(Exchange):
params['stopPrice'] = stop_price
amount = self.amount_to_precision(pair, amount)
self._lev_prep(pair, leverage)
self._lev_prep(pair, leverage, side)
order = self._api.create_order(symbol=pair, type=ordertype, side=side,
amount=amount, params=params)
self._log_exchange_response('create_stoploss_order', order)

View File

@ -3,7 +3,7 @@ from typing import Dict, List, Tuple
from freqtrade.enums import MarginMode, TradingMode
from freqtrade.exchange import Exchange
from freqtrade.exceptions import OperationalException
logger = logging.getLogger(__name__)
@ -26,3 +26,22 @@ class Okex(Exchange):
# (TradingMode.FUTURES, MarginMode.CROSS),
# (TradingMode.FUTURES, MarginMode.ISOLATED)
]
def _lev_prep(
self,
pair: str,
leverage: float,
side: str # buy or sell
):
if self.trading_mode != TradingMode.SPOT:
if self.margin_mode is None:
raise OperationalException(
f"{self.name}.margin_mode must be set for {self.trading_mode.value}"
)
self._api.set_leverage(
leverage,
pair,
params={
"mgnMode": self.margin_mode.value,
"posSide": "long" if side == "buy" else "short",
})