Update get_market_leverage_tiers to be async

This commit is contained in:
Matthias 2022-05-31 08:48:34 +00:00
parent d8df9fdccf
commit cce8d1aa4d

View File

@ -2131,10 +2131,11 @@ class Exchange:
except ccxt.BaseError as e: except ccxt.BaseError as e:
raise OperationalException(e) from e raise OperationalException(e) from e
@retrier @retrier_async
def get_market_leverage_tiers(self, symbol) -> List[Dict]: async def get_market_leverage_tiers(self, symbol: str) -> Tuple[str, List[Dict]]:
try: try:
return self._api.fetch_market_leverage_tiers(symbol) tier = await self._api_async.fetch_market_leverage_tiers(symbol)
return symbol, tier
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:
@ -2168,8 +2169,14 @@ class Exchange:
f"Initializing leverage_tiers for {len(symbols)} markets. " f"Initializing leverage_tiers for {len(symbols)} markets. "
"This will take about a minute.") "This will take about a minute.")
for symbol in sorted(symbols): coros = [self.get_market_leverage_tiers(symbol) for symbol in sorted(symbols)]
tiers[symbol] = self.get_market_leverage_tiers(symbol)
for input_coro in chunks(coros, 100):
results = self.loop.run_until_complete(
asyncio.gather(*input_coro, return_exceptions=True))
for symbol, res in results:
tiers[symbol] = res
logger.info(f"Done initializing {len(symbols)} markets.") logger.info(f"Done initializing {len(symbols)} markets.")