mirror of
https://github.com/freqtrade/freqtrade.git
synced 2025-12-15 20:31:43 +00:00
Only load markets once
Increases startup speed by 6s on binance (from 9 to 3s).
This commit is contained in:
@@ -530,14 +530,19 @@ class Exchange:
|
|||||||
amount, self.get_precision_amount(pair), self.precisionMode, contract_size
|
amount, self.get_precision_amount(pair), self.precisionMode, contract_size
|
||||||
)
|
)
|
||||||
|
|
||||||
def _load_async_markets(self, reload: bool = False) -> None:
|
def _load_async_markets(self, reload: bool = False) -> Dict[str, Any]:
|
||||||
try:
|
try:
|
||||||
if self._api_async:
|
if self._api_async:
|
||||||
self.loop.run_until_complete(self._api_async.load_markets(reload=reload, params={}))
|
markets = self.loop.run_until_complete(
|
||||||
|
self._api_async.load_markets(reload=reload, params={})
|
||||||
|
)
|
||||||
|
|
||||||
except (asyncio.TimeoutError, ccxt.BaseError) as e:
|
if isinstance(markets, Exception):
|
||||||
logger.warning("Could not load async markets. Reason: %s", e)
|
raise markets
|
||||||
return
|
return markets
|
||||||
|
except asyncio.TimeoutError as e:
|
||||||
|
logger.warning("Could not load markets. Reason: %s", e)
|
||||||
|
raise TemporaryError from e
|
||||||
|
|
||||||
def reload_markets(self, force: bool = False, *, load_leverage_tiers: bool = True) -> None:
|
def reload_markets(self, force: bool = False, *, load_leverage_tiers: bool = True) -> None:
|
||||||
"""
|
"""
|
||||||
@@ -554,9 +559,9 @@ class Exchange:
|
|||||||
return None
|
return None
|
||||||
logger.debug("Performing scheduled market reload..")
|
logger.debug("Performing scheduled market reload..")
|
||||||
try:
|
try:
|
||||||
self._markets = self._api.load_markets(reload=True, params={})
|
# Reload async markets, then assign them to sync api
|
||||||
# Also reload async markets to avoid issues with newly listed pairs
|
self._markets = self._load_async_markets(reload=True)
|
||||||
self._load_async_markets(reload=True)
|
self._api.set_markets(self._api_async.markets, self._api_async.currencies)
|
||||||
self._last_markets_refresh = dt_ts()
|
self._last_markets_refresh = dt_ts()
|
||||||
|
|
||||||
if is_initial and self._ft_has["needs_trading_fees"]:
|
if is_initial and self._ft_has["needs_trading_fees"]:
|
||||||
@@ -564,7 +569,7 @@ class Exchange:
|
|||||||
|
|
||||||
if load_leverage_tiers and self.trading_mode == TradingMode.FUTURES:
|
if load_leverage_tiers and self.trading_mode == TradingMode.FUTURES:
|
||||||
self.fill_leverage_tiers()
|
self.fill_leverage_tiers()
|
||||||
except ccxt.BaseError:
|
except (ccxt.BaseError, TemporaryError):
|
||||||
logger.exception("Could not load markets.")
|
logger.exception("Could not load markets.")
|
||||||
|
|
||||||
def validate_stakecurrency(self, stake_currency: str) -> None:
|
def validate_stakecurrency(self, stake_currency: str) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user