chore: use loop_lock for all run_until_complete usages

This commit is contained in:
Matthias
2025-02-02 20:10:57 +01:00
parent 8cad9c8436
commit 2bfd66d271
2 changed files with 25 additions and 21 deletions

View File

@@ -140,6 +140,7 @@ class Binance(Exchange):
:param candle_type: Any of the enum CandleType (must match trading mode!) :param candle_type: Any of the enum CandleType (must match trading mode!)
""" """
if is_new_pair: if is_new_pair:
with self._loop_lock:
x = self.loop.run_until_complete( x = self.loop.run_until_complete(
self._async_get_candle_history(pair, timeframe, candle_type, 0) self._async_get_candle_history(pair, timeframe, candle_type, 0)
) )
@@ -201,6 +202,7 @@ class Binance(Exchange):
""" """
Fastly fetch OHLCV data by leveraging https://data.binance.vision. Fastly fetch OHLCV data by leveraging https://data.binance.vision.
""" """
with self._loop_lock:
df = self.loop.run_until_complete( df = self.loop.run_until_complete(
download_archive_ohlcv( download_archive_ohlcv(
candle_type=candle_type, candle_type=candle_type,

View File

@@ -648,6 +648,7 @@ class Exchange:
def _load_async_markets(self, reload: bool = False) -> dict[str, Any]: def _load_async_markets(self, reload: bool = False) -> dict[str, Any]:
try: try:
with self._loop_lock:
markets = self.loop.run_until_complete(self._api_reload_markets(reload=reload)) markets = self.loop.run_until_complete(self._api_reload_markets(reload=reload))
if isinstance(markets, Exception): if isinstance(markets, Exception):
@@ -2342,6 +2343,7 @@ class Exchange:
:param until_ms: Timestamp in milliseconds to get history up to :param until_ms: Timestamp in milliseconds to get history up to
:return: Dataframe with candle (OHLCV) data :return: Dataframe with candle (OHLCV) data
""" """
with self._loop_lock:
pair, _, _, data, _ = self.loop.run_until_complete( pair, _, _, data, _ = self.loop.run_until_complete(
self._async_get_historic_ohlcv( self._async_get_historic_ohlcv(
pair=pair, pair=pair,