From 102c1e799ccf86e215426689046ad0468eee1ab8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 7 Feb 2023 20:51:55 +0100 Subject: [PATCH] realign binance set_leverage override --- freqtrade/exchange/binance.py | 28 +--------------------------- freqtrade/exchange/exchange.py | 5 ++++- 2 files changed, 5 insertions(+), 28 deletions(-) diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index 22dfdc1d1..d362a75cd 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -32,6 +32,7 @@ class Binance(Exchange): _ft_has_futures: Dict = { "stoploss_order_types": {"limit": "stop", "market": "stop_market"}, "tickers_have_price": False, + "floor_leverage": True, } _supported_trading_mode_margin_pairs: List[Tuple[TradingMode, MarginMode]] = [ @@ -83,33 +84,6 @@ class Binance(Exchange): except ccxt.BaseError as 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, since_ms: int, candle_type: CandleType, is_new_pair: bool = False, raise_: bool = False, diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index 8ac2abf6c..5ee51d686 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -7,6 +7,7 @@ import inspect import logging from copy import deepcopy from datetime import datetime, timedelta, timezone +from math import floor from threading import Lock 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"): # Some exchanges only support one margin_mode type return - + if self._ft_has.get('floor_leverage', False) is True: + # Rounding for binance ... + leverage = floor(leverage) try: res = self._api.set_leverage(symbol=pair, leverage=leverage) self._log_exchange_response('set_leverage', res)