summaryrefslogtreecommitdiff
path: root/services/data-collector/src/data_collector/ws_factory.py
blob: b8e27190f082ac50153babaf2ae7518f19216c82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""WebSocket factory for exchange-specific connections."""
import logging

from data_collector.binance_ws import BinanceWebSocket

logger = logging.getLogger(__name__)

# Supported exchanges for WebSocket streaming
SUPPORTED_WS = {"binance": BinanceWebSocket}


def create_websocket(exchange_id: str, **kwargs):
    """Create an exchange-specific WebSocket handler.

    Args:
        exchange_id: Exchange identifier (e.g. 'binance')
        **kwargs: Passed to the WebSocket constructor (symbols, timeframe, on_candle)

    Returns:
        WebSocket handler instance

    Raises:
        ValueError: If exchange is not supported for WebSocket streaming
    """
    ws_cls = SUPPORTED_WS.get(exchange_id)
    if ws_cls is None:
        supported = ", ".join(sorted(SUPPORTED_WS.keys()))
        raise ValueError(
            f"WebSocket streaming not supported for '{exchange_id}'. "
            f"Supported: {supported}. "
            f"Use REST polling as fallback for unsupported exchanges."
        )
    return ws_cls(**kwargs)