diff --git a/freqtrade/exchange/binance.py b/freqtrade/exchange/binance.py index f1b9db279..e9c44a41e 100644 --- a/freqtrade/exchange/binance.py +++ b/freqtrade/exchange/binance.py @@ -140,9 +140,10 @@ class Binance(Exchange): :param candle_type: Any of the enum CandleType (must match trading mode!) """ if is_new_pair: - x = self.loop.run_until_complete( - self._async_get_candle_history(pair, timeframe, candle_type, 0) - ) + with self._loop_lock: + x = self.loop.run_until_complete( + self._async_get_candle_history(pair, timeframe, candle_type, 0) + ) if x and x[3] and x[3][0] and x[3][0][0] > since_ms: # Set starting date to first available candle. since_ms = x[3][0][0] @@ -201,16 +202,17 @@ class Binance(Exchange): """ Fastly fetch OHLCV data by leveraging https://data.binance.vision. """ - df = self.loop.run_until_complete( - download_archive_ohlcv( - candle_type=candle_type, - pair=pair, - timeframe=timeframe, - since_ms=since_ms, - until_ms=until_ms, - markets=self.markets, + with self._loop_lock: + df = self.loop.run_until_complete( + download_archive_ohlcv( + candle_type=candle_type, + pair=pair, + timeframe=timeframe, + since_ms=since_ms, + until_ms=until_ms, + markets=self.markets, + ) ) - ) # download the remaining data from rest API if df.empty: diff --git a/freqtrade/exchange/exchange.py b/freqtrade/exchange/exchange.py index b7d94e277..175f89c0e 100644 --- a/freqtrade/exchange/exchange.py +++ b/freqtrade/exchange/exchange.py @@ -648,7 +648,8 @@ class Exchange: def _load_async_markets(self, reload: bool = False) -> dict[str, Any]: try: - markets = self.loop.run_until_complete(self._api_reload_markets(reload=reload)) + with self._loop_lock: + markets = self.loop.run_until_complete(self._api_reload_markets(reload=reload)) if isinstance(markets, Exception): raise markets @@ -2342,15 +2343,16 @@ class Exchange: :param until_ms: Timestamp in milliseconds to get history up to :return: Dataframe with candle (OHLCV) data """ - pair, _, _, data, _ = self.loop.run_until_complete( - self._async_get_historic_ohlcv( - pair=pair, - timeframe=timeframe, - since_ms=since_ms, - until_ms=until_ms, - candle_type=candle_type, + with self._loop_lock: + pair, _, _, data, _ = self.loop.run_until_complete( + self._async_get_historic_ohlcv( + pair=pair, + timeframe=timeframe, + since_ms=since_ms, + until_ms=until_ms, + candle_type=candle_type, + ) ) - ) logger.debug(f"Downloaded data for {pair} from ccxt with length {len(data)}.") return ohlcv_to_dataframe(data, timeframe, pair, fill_missing=False, drop_incomplete=True)