Adjusted _get_funding_fee_method

This commit is contained in:
Sam Germain 2021-10-05 17:25:31 -06:00
parent cba0a8cee6
commit badc0fa445
2 changed files with 8 additions and 32 deletions

View File

@ -242,12 +242,12 @@ class Binance(Exchange):
- interest rate: 0.03% daily, BNBUSDT, LINKUSDT, and LTCUSDT are 0% - interest rate: 0.03% daily, BNBUSDT, LINKUSDT, and LTCUSDT are 0%
- premium: varies by price difference between the perpetual contract and mark price - premium: varies by price difference between the perpetual contract and mark price
""" """
if premium_index is None: if mark_price is None:
raise OperationalException("Premium index cannot be None for Binance._get_funding_fee") raise OperationalException("Mark price cannot be None for Binance._get_funding_fee")
nominal_value = mark_price * contract_size nominal_value = mark_price * contract_size
funding_rate = self._calculate_funding_rate(pair, premium_index)
if funding_rate is None: if funding_rate is None:
raise OperationalException("Funding rate should never be none on Binance") raise OperationalException(
"Funding rate should never be none on Binance._get_funding_fee")
return nominal_value * funding_rate return nominal_value * funding_rate
async def _async_get_historic_ohlcv(self, pair: str, timeframe: str, async def _async_get_historic_ohlcv(self, pair: str, timeframe: str,

View File

@ -89,6 +89,7 @@ class Exchange:
self._api: ccxt.Exchange = None self._api: ccxt.Exchange = None
self._api_async: ccxt_async.Exchange = None self._api_async: ccxt_async.Exchange = None
self._markets: Dict = {} self._markets: Dict = {}
self._leverage_brackets: Dict = {}
self._config.update(config) self._config.update(config)
@ -157,6 +158,9 @@ 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:
@ -179,10 +183,6 @@ 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
self._leverage_brackets: Dict = {}
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
@ -1635,30 +1635,6 @@ 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_mark_price(self, pair: str, date: datetime) -> float: def _get_mark_price(self, pair: str, date: datetime) -> float:
raise OperationalException(f'_get_mark_price has not been implemented on {self.name}') raise OperationalException(f'_get_mark_price has not been implemented on {self.name}')