Add fill_leverage_brackets and get_max_leverage back in
This commit is contained in:
parent
d99e0dac7b
commit
60478cb213
@ -75,7 +75,6 @@ class Exchange:
|
|||||||
# funding_fee_times is currently unused, but should ideally be used to properly
|
# funding_fee_times is currently unused, but should ideally be used to properly
|
||||||
# schedule refresh times
|
# schedule refresh times
|
||||||
funding_fee_times: List[int] = [] # hours of the day
|
funding_fee_times: List[int] = [] # hours of the day
|
||||||
funding_rate_history: Dict = {}
|
|
||||||
|
|
||||||
_supported_trading_mode_collateral_pairs: List[Tuple[TradingMode, Collateral]] = [
|
_supported_trading_mode_collateral_pairs: List[Tuple[TradingMode, Collateral]] = [
|
||||||
# TradingMode.SPOT always supported and not required in this list
|
# TradingMode.SPOT always supported and not required in this list
|
||||||
@ -160,9 +159,6 @@ class Exchange:
|
|||||||
self._api_async = self._init_ccxt(
|
self._api_async = self._init_ccxt(
|
||||||
exchange_config, ccxt_async, ccxt_kwargs=ccxt_async_config)
|
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)
|
logger.info('Using Exchange "%s"', self.name)
|
||||||
|
|
||||||
if validate:
|
if validate:
|
||||||
@ -185,6 +181,9 @@ class Exchange:
|
|||||||
self.markets_refresh_interval: int = exchange_config.get(
|
self.markets_refresh_interval: int = exchange_config.get(
|
||||||
"markets_refresh_interval", 60) * 60
|
"markets_refresh_interval", 60) * 60
|
||||||
|
|
||||||
|
if self.trading_mode != TradingMode.SPOT:
|
||||||
|
self.fill_leverage_brackets()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
"""
|
"""
|
||||||
Destructor - clean up async stuff
|
Destructor - clean up async stuff
|
||||||
@ -1637,6 +1636,30 @@ class Exchange:
|
|||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from 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(
|
def _get_funding_fee(
|
||||||
self,
|
self,
|
||||||
contract_size: float,
|
contract_size: float,
|
||||||
|
@ -169,21 +169,6 @@ class Ftx(Exchange):
|
|||||||
return safe_value_fallback2(order, order, 'id_stop', 'id')
|
return safe_value_fallback2(order, order, 'id_stop', 'id')
|
||||||
return order['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(
|
def _get_mark_price_history(
|
||||||
self,
|
self,
|
||||||
pair: str,
|
pair: str,
|
||||||
|
@ -125,7 +125,6 @@ class Backtesting:
|
|||||||
|
|
||||||
self.progress = BTProgress()
|
self.progress = BTProgress()
|
||||||
self.abort = False
|
self.abort = False
|
||||||
|
|
||||||
self.init_backtest()
|
self.init_backtest()
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
|
@ -707,7 +707,6 @@ class LocalTrade():
|
|||||||
return float(self._calc_base_close(amount, rate, fee) - total_interest)
|
return float(self._calc_base_close(amount, rate, fee) - total_interest)
|
||||||
|
|
||||||
elif (trading_mode == TradingMode.FUTURES):
|
elif (trading_mode == TradingMode.FUTURES):
|
||||||
self.add_funding_fees()
|
|
||||||
funding_fees = self.funding_fees or 0.0
|
funding_fees = self.funding_fees or 0.0
|
||||||
if self.is_short:
|
if self.is_short:
|
||||||
return float(self._calc_base_close(amount, rate, fee)) - funding_fees
|
return float(self._calc_base_close(amount, rate, fee)) - funding_fees
|
||||||
@ -789,19 +788,6 @@ class LocalTrade():
|
|||||||
else:
|
else:
|
||||||
return None
|
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
|
@staticmethod
|
||||||
def get_trades_proxy(*, pair: str = None, is_open: bool = None,
|
def get_trades_proxy(*, pair: str = None, is_open: bool = None,
|
||||||
open_date: datetime = None, close_date: datetime = None,
|
open_date: datetime = None, close_date: datetime = None,
|
||||||
|
@ -250,20 +250,3 @@ def test_get_order_id(mocker, default_conf):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert exchange.get_order_id_conditional(order) == '1111'
|
assert exchange.get_order_id_conditional(order) == '1111'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('pair,nominal_value,max_lev', [
|
|
||||||
("ADA/BTC", 0.0, 20.0),
|
|
||||||
("BTC/EUR", 100.0, 20.0),
|
|
||||||
("ZEC/USD", 173.31, 20.0),
|
|
||||||
])
|
|
||||||
def test_get_max_leverage_ftx(default_conf, mocker, pair, nominal_value, max_lev):
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="ftx")
|
|
||||||
assert exchange.get_max_leverage(pair, nominal_value) == max_lev
|
|
||||||
|
|
||||||
|
|
||||||
def test_fill_leverage_brackets_ftx(default_conf, mocker):
|
|
||||||
# FTX only has one account wide leverage, so there's no leverage brackets
|
|
||||||
exchange = get_patched_exchange(mocker, default_conf, id="ftx")
|
|
||||||
exchange.fill_leverage_brackets()
|
|
||||||
assert exchange._leverage_brackets == {}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user