From 60cfda5d5236484149ffef5b1dc1d16192f235cd Mon Sep 17 00:00:00 2001 From: Matthias Date: Mon, 7 Nov 2022 07:07:15 +0100 Subject: [PATCH] Add very basic exception handling --- freqtrade/exchange/exchange_ws.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/freqtrade/exchange/exchange_ws.py b/freqtrade/exchange/exchange_ws.py index afa0b6de3..b5bbb663d 100644 --- a/freqtrade/exchange/exchange_ws.py +++ b/freqtrade/exchange/exchange_ws.py @@ -6,6 +6,8 @@ from datetime import datetime from threading import Thread from typing import Dict, List, Set, Tuple +import ccxt + from freqtrade.constants import Config from freqtrade.enums.candletype import CandleType from freqtrade.exchange.exchange import timeframe_to_seconds @@ -70,13 +72,18 @@ class ExchangeWS(): async def continuously_async_watch_ohlcv( self, pair: str, timeframe: str, candle_type: CandleType) -> None: - - while (pair, timeframe, candle_type) in self._pairs_watching: - start = time.time() - data = await self.ccxt_object.watch_ohlcv(pair, timeframe) - self.pairs_last_refresh[(pair, timeframe, candle_type)] = time.time() - # logger.info( - # f"watch done {pair}, {timeframe}, data {len(data)} in {time.time() - start:.2f}s") + try: + while (pair, timeframe, candle_type) in self._pairs_watching: + start = time.time() + data = await self.ccxt_object.watch_ohlcv(pair, timeframe) + self.pairs_last_refresh[(pair, timeframe, candle_type)] = time.time() + # logger.info( + # f"watch done {pair}, {timeframe}, data {len(data)} " + # f"in {time.time() - start:.2f}s") + except ccxt.BaseError: + logger.exception("Exception in continuously_async_watch_ohlcv") + finally: + self._pairs_watching.discard((pair, timeframe, candle_type)) def schedule_ohlcv(self, pair: str, timeframe: str, candle_type: CandleType) -> None: self._pairs_watching.add((pair, timeframe, candle_type))