exchange.get_leverage_tiers and exchange.get_market_leverage_tiers
This commit is contained in:
parent
c7e87e86e2
commit
6cd01c45d5
@ -1873,22 +1873,40 @@ class Exchange:
|
|||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
@retrier
|
@retrier
|
||||||
def load_leverage_tiers(self) -> Dict[str, List[Dict]]:
|
def get_leverage_tiers(self) -> Dict[str, List[Dict]]:
|
||||||
if self.trading_mode == TradingMode.FUTURES:
|
|
||||||
if self.exchange_has('fetchLeverageTiers'):
|
|
||||||
try:
|
try:
|
||||||
return self._api.fetch_leverage_tiers()
|
return self._api.fetch_leverage_tiers()
|
||||||
except ccxt.DDoSProtection as e:
|
except ccxt.DDoSProtection as e:
|
||||||
raise DDosProtection(e) from e
|
raise DDosProtection(e) from e
|
||||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
raise TemporaryError(
|
raise TemporaryError(
|
||||||
f'Could not load leverage tiers due to {e.__class__.__name__}.'
|
f'Could not load leverage tiers due to {e.__class__.__name__}. Message: {e}'
|
||||||
f'Message: {e}'
|
|
||||||
) from e
|
) from e
|
||||||
except ccxt.BaseError as e:
|
except ccxt.BaseError as e:
|
||||||
raise OperationalException(e) from e
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
|
@retrier
|
||||||
|
def get_market_leverage_tiers(self, symbol) -> List[Dict]:
|
||||||
|
try:
|
||||||
|
return self._api.fetch_market_leverage_tiers(symbol)
|
||||||
|
except ccxt.DDoSProtection as e:
|
||||||
|
raise DDosProtection(e) from e
|
||||||
|
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
||||||
|
raise TemporaryError(
|
||||||
|
f'Could not load leverage tiers for {symbol}'
|
||||||
|
f' due to {e.__class__.__name__}. Message: {e}'
|
||||||
|
) from e
|
||||||
|
except ccxt.BaseError as e:
|
||||||
|
raise OperationalException(e) from e
|
||||||
|
|
||||||
|
def load_leverage_tiers(self) -> Dict[str, List[Dict]]:
|
||||||
|
if self.trading_mode == TradingMode.FUTURES:
|
||||||
|
if self.exchange_has('fetchLeverageTiers'):
|
||||||
|
# Fetch all leverage tiers at once
|
||||||
|
return self.get_leverage_tiers()
|
||||||
elif self.exchange_has('fetchMarketLeverageTiers'):
|
elif self.exchange_has('fetchMarketLeverageTiers'):
|
||||||
# * This is slow(~45s) on Okex, makes ~90 api calls to load all linear swap markets
|
# Must fetch the leverage tiers for each market separately
|
||||||
|
# * This is slow(~45s) on Okx, makes ~90 api calls to load all linear swap markets
|
||||||
markets = self.markets
|
markets = self.markets
|
||||||
symbols = []
|
symbols = []
|
||||||
|
|
||||||
@ -1905,18 +1923,8 @@ class Exchange:
|
|||||||
"This will take about a minute.")
|
"This will take about a minute.")
|
||||||
|
|
||||||
for symbol in sorted(symbols):
|
for symbol in sorted(symbols):
|
||||||
try:
|
tiers[symbol] = self.get_market_leverage_tiers(symbol)
|
||||||
res = self._api.fetch_market_leverage_tiers(symbol)
|
|
||||||
tiers[symbol] = res[symbol]
|
|
||||||
except ccxt.DDoSProtection as e:
|
|
||||||
raise DDosProtection(e) from e
|
|
||||||
except (ccxt.NetworkError, ccxt.ExchangeError) as e:
|
|
||||||
raise TemporaryError(
|
|
||||||
f'Could not load leverage tiers for {symbol}'
|
|
||||||
f' due to {e.__class__.__name__}. Message: {e}'
|
|
||||||
) from e
|
|
||||||
except ccxt.BaseError as e:
|
|
||||||
raise OperationalException(e) from e
|
|
||||||
logger.info(f"Done initializing {len(symbols)} markets.")
|
logger.info(f"Done initializing {len(symbols)} markets.")
|
||||||
|
|
||||||
return tiers
|
return tiers
|
||||||
|
Loading…
Reference in New Issue
Block a user