diff --git a/openbb_platform/extensions/websockets/openbb_websockets/client.py b/openbb_platform/extensions/websockets/openbb_websockets/client.py index 714b175125a..e5b90918585 100644 --- a/openbb_platform/extensions/websockets/openbb_websockets/client.py +++ b/openbb_platform/extensions/websockets/openbb_websockets/client.py @@ -166,6 +166,8 @@ class WebSocketClient: # pylint: disable=import-outside-toplevel import os + self._exception = None + if self.is_running: self.disconnect() if self.is_broadcasting: diff --git a/openbb_platform/extensions/websockets/openbb_websockets/websockets_router.py b/openbb_platform/extensions/websockets/openbb_websockets/websockets_router.py index 91fd66967cd..e75e7d9457f 100644 --- a/openbb_platform/extensions/websockets/openbb_websockets/websockets_router.py +++ b/openbb_platform/extensions/websockets/openbb_websockets/websockets_router.py @@ -60,7 +60,6 @@ async def create_connection( if not client.is_running: if client._exception: exc = getattr(client, "_exception", None) - delattr(client, "_exception") client._atexit() if isinstance(exc, UnauthorizedError): raise exc @@ -159,14 +158,19 @@ async def subscribe( """ if not await check_auth(name, auth_token): raise OpenBBError("Error finding client.") + client = connected_clients[name] symbols = client.symbol.split(",") + if symbols and symbol in symbols: raise OpenBBError(f"Client {name} already subscribed to {symbol}.") + client.subscribe(symbol) - # await asyncio.sleep(2) + await asyncio.sleep(1) + if client.is_running: return OBBject(results=f"Added {symbol} to client {name} connection.") + client.logger.error( f"Client {name} failed to subscribe to {symbol} and is not running." )