From 08e1a616a0a0b38a14f8ade1439e6e6985350260 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 11 Feb 2025 08:18:47 +0100 Subject: [PATCH] feat: use unwatch to stop watching a websocket --- freqtrade/exchange/exchange_ws.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/freqtrade/exchange/exchange_ws.py b/freqtrade/exchange/exchange_ws.py index e1fc37ff3..925e3b4fc 100644 --- a/freqtrade/exchange/exchange_ws.py +++ b/freqtrade/exchange/exchange_ws.py @@ -138,6 +138,13 @@ class ExchangeWS: ) ) + async def _unwatch_ohlcv(self, pair: str, timeframe: str, candle_type: CandleType) -> None: + try: + await self.ccxt_object.un_watch_ohlcv_for_symbols([[pair, timeframe]]) + except ccxt.NotSupported as e: + logger.debug("un_watch_ohlcv_for_symbols not supported: %s", e) + pass + def _continuous_stopped( self, task: asyncio.Task, pair: str, timeframe: str, candle_type: CandleType ): @@ -150,6 +157,10 @@ class ExchangeWS: result = str(result1) logger.info(f"{pair}, {timeframe}, {candle_type} - Task finished - {result}") + asyncio.run_coroutine_threadsafe( + self._unwatch_ohlcv(pair, timeframe, candle_type), loop=self._loop + ) + self._klines_scheduled.discard((pair, timeframe, candle_type)) self._pop_history((pair, timeframe, candle_type))