Add fill_leverage_brackets and get_max_leverage back in

This commit is contained in:
Sam Germain
2021-10-23 22:01:44 -06:00
parent d99e0dac7b
commit 60478cb213
5 changed files with 27 additions and 51 deletions

View File

@@ -75,7 +75,6 @@ class Exchange:
# funding_fee_times is currently unused, but should ideally be used to properly
# schedule refresh times
funding_fee_times: List[int] = [] # hours of the day
funding_rate_history: Dict = {}
_supported_trading_mode_collateral_pairs: List[Tuple[TradingMode, Collateral]] = [
# TradingMode.SPOT always supported and not required in this list
@@ -160,9 +159,6 @@ class Exchange:
self._api_async = self._init_ccxt(
exchange_config, ccxt_async, ccxt_kwargs=ccxt_async_config)
if self.trading_mode != TradingMode.SPOT:
self.fill_leverage_brackets()
logger.info('Using Exchange "%s"', self.name)
if validate:
@@ -185,6 +181,9 @@ class Exchange:
self.markets_refresh_interval: int = exchange_config.get(
"markets_refresh_interval", 60) * 60
if self.trading_mode != TradingMode.SPOT:
self.fill_leverage_brackets()
def __del__(self):
"""
Destructor - clean up async stuff
@@ -1637,6 +1636,30 @@ class Exchange:
except ccxt.BaseError as e:
raise OperationalException(e) from e
def fill_leverage_brackets(self):
"""
Assigns property _leverage_brackets to a dictionary of information about the leverage
allowed on each pair
Not used if the exchange has a static max leverage value for the account or each pair
"""
return
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
"""
Returns the maximum leverage that a pair can be traded at
:param pair: The base/quote currency pair being traded
:nominal_value: The total value of the trade in quote currency (collateral + debt)
"""
market = self.markets[pair]
if (
'limits' in market and
'leverage' in market['limits'] and
'max' in market['limits']['leverage']
):
return market['limits']['leverage']['max']
else:
return 1.0
def _get_funding_fee(
self,
contract_size: float,

View File

@@ -169,21 +169,6 @@ class Ftx(Exchange):
return safe_value_fallback2(order, order, 'id_stop', 'id')
return order['id']
def fill_leverage_brackets(self):
"""
FTX leverage is static across the account, and doesn't change from pair to pair,
so _leverage_brackets doesn't need to be set
"""
return
def get_max_leverage(self, pair: Optional[str], nominal_value: Optional[float]) -> float:
"""
Returns the maximum leverage that a pair can be traded at, which is always 20 on ftx
:param pair: Here for super method, not used on FTX
:nominal_value: Here for super method, not used on FTX
"""
return 20.0
def _get_mark_price_history(
self,
pair: str,

View File

@@ -125,7 +125,6 @@ class Backtesting:
self.progress = BTProgress()
self.abort = False
self.init_backtest()
def __del__(self):

View File

@@ -707,7 +707,6 @@ class LocalTrade():
return float(self._calc_base_close(amount, rate, fee) - total_interest)
elif (trading_mode == TradingMode.FUTURES):
self.add_funding_fees()
funding_fees = self.funding_fees or 0.0
if self.is_short:
return float(self._calc_base_close(amount, rate, fee)) - funding_fees
@@ -789,19 +788,6 @@ class LocalTrade():
else:
return None
def add_funding_fees(self):
if self.trading_mode == TradingMode.FUTURES:
# TODO-lev: Calculate this correctly and add it
# if self.config['runmode'].value in ('backtest', 'hyperopt'):
# self.funding_fees = getattr(Exchange, self.exchange).calculate_funding_fees(
# self.exchange,
# self.pair,
# self.amount,
# self.open_date_utc,
# self.close_date_utc
# )
return
@staticmethod
def get_trades_proxy(*, pair: str = None, is_open: bool = None,
open_date: datetime = None, close_date: datetime = None,