refactor: simplify ws exchange handling

This commit is contained in:
Matthias
2025-05-10 13:30:26 +02:00
parent 5f907d4219
commit 8dc278f1a0
2 changed files with 4 additions and 8 deletions

View File

@@ -267,11 +267,11 @@ class Exchange:
exchange_conf.get("ccxt_async_config", {}), ccxt_async_config exchange_conf.get("ccxt_async_config", {}), ccxt_async_config
) )
self._api_async = self._init_ccxt(exchange_conf, False, ccxt_async_config) self._api_async = self._init_ccxt(exchange_conf, False, ccxt_async_config)
self._has_watch_ohlcv = self.exchange_has("watchOHLCV") and self._ft_has["ws_enabled"] _has_watch_ohlcv = self.exchange_has("watchOHLCV") and self._ft_has["ws_enabled"]
if ( if (
self._config["runmode"] in TRADE_MODES self._config["runmode"] in TRADE_MODES
and exchange_conf.get("enable_ws", True) and exchange_conf.get("enable_ws", True)
and self._has_watch_ohlcv and _has_watch_ohlcv
): ):
self._ws_async = self._init_ccxt(exchange_conf, False, ccxt_async_config) self._ws_async = self._init_ccxt(exchange_conf, False, ccxt_async_config)
self._exchange_ws = ExchangeWS(self._config, self._ws_async) self._exchange_ws = ExchangeWS(self._config, self._ws_async)
@@ -2449,11 +2449,7 @@ class Exchange:
Check if we can use websocket for this pair. Check if we can use websocket for this pair.
Acts as typeguard for exchangeWs Acts as typeguard for exchangeWs
""" """
if ( if exchange_ws and candle_type in (CandleType.SPOT, CandleType.FUTURES):
self._has_watch_ohlcv
and exchange_ws
and candle_type in (CandleType.SPOT, CandleType.FUTURES)
):
return True return True
return False return False

View File

@@ -599,7 +599,7 @@ def exchange_ws(request, exchange_conf, exchange_mode, class_mocker):
else: else:
pytest.skip("Exchange does not support futures.") pytest.skip("Exchange does not support futures.")
if not exchange._has_watch_ohlcv: if not exchange._exchange_ws:
pytest.skip("Exchange does not support watch_ohlcv.") pytest.skip("Exchange does not support watch_ohlcv.")
yield exchange, name, pair yield exchange, name, pair
exchange.close() exchange.close()