realign binance set_leverage override
This commit is contained in:
parent
980ffa6bfb
commit
102c1e799c
@ -32,6 +32,7 @@ class Binance(Exchange):
|
|||||||
_ft_has_futures: Dict = {
|
_ft_has_futures: Dict = {
|
||||||
"stoploss_order_types": {"limit": "stop", "market": "stop_market"},
|
"stoploss_order_types": {"limit": "stop", "market": "stop_market"},
|
||||||
"tickers_have_price": False,
|
"tickers_have_price": False,
|
||||||
|
"floor_leverage": True,
|
||||||
}
|
}
|
||||||
|
|
||||||
_supported_trading_mode_margin_pairs: List[Tuple[TradingMode, MarginMode]] = [
|
_supported_trading_mode_margin_pairs: List[Tuple[TradingMode, MarginMode]] = [
|
||||||
@ -83,33 +84,6 @@ class Binance(Exchange):
|
|||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
@retrier
|
|
||||||
def _set_leverage(
|
|
||||||
self,
|
|
||||||
leverage: float,
|
|
||||||
pair: Optional[str] = None,
|
|
||||||
trading_mode: Optional[TradingMode] = None,
|
|
||||||
accept_fail: bool = False,
|
|
||||||
):
|
|
||||||
"""
|
|
||||||
Set's the leverage before making a trade, in order to not
|
|
||||||
have the same leverage on every trade
|
|
||||||
"""
|
|
||||||
trading_mode = trading_mode or self.trading_mode
|
|
||||||
|
|
||||||
if self._config['dry_run'] or trading_mode != TradingMode.FUTURES:
|
|
||||||
return
|
|
||||||
|
|
||||||
try:
|
|
||||||
self._api.set_leverage(symbol=pair, leverage=round(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
|
|
||||||
|
|
||||||
async def _async_get_historic_ohlcv(self, pair: str, timeframe: str,
|
async def _async_get_historic_ohlcv(self, pair: str, timeframe: str,
|
||||||
since_ms: int, candle_type: CandleType,
|
since_ms: int, candle_type: CandleType,
|
||||||
is_new_pair: bool = False, raise_: bool = False,
|
is_new_pair: bool = False, raise_: bool = False,
|
||||||
|
@ -7,6 +7,7 @@ import inspect
|
|||||||
import logging
|
import logging
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
|
from math import floor
|
||||||
from threading import Lock
|
from threading import Lock
|
||||||
from typing import Any, Coroutine, Dict, List, Literal, Optional, Tuple, Union
|
from typing import Any, Coroutine, Dict, List, Literal, Optional, Tuple, Union
|
||||||
|
|
||||||
@ -2494,7 +2495,9 @@ class Exchange:
|
|||||||
if self._config['dry_run'] or not self.exchange_has("setLeverage"):
|
if self._config['dry_run'] or not self.exchange_has("setLeverage"):
|
||||||
# Some exchanges only support one margin_mode type
|
# Some exchanges only support one margin_mode type
|
||||||
return
|
return
|
||||||
|
if self._ft_has.get('floor_leverage', False) is True:
|
||||||
|
# Rounding for binance ...
|
||||||
|
leverage = floor(leverage)
|
||||||
try:
|
try:
|
||||||
res = self._api.set_leverage(symbol=pair, leverage=leverage)
|
res = self._api.set_leverage(symbol=pair, leverage=leverage)
|
||||||
self._log_exchange_response('set_leverage', res)
|
self._log_exchange_response('set_leverage', res)
|
||||||
|
Loading…
Reference in New Issue
Block a user