@@ -84,7 +84,7 @@ def __init__(self, host: str, access_token: Optional[str] = None, api_key: Optio
8484 # Track active subscriptions by (method, symbol_key) -> request_id
8585 # to avoid duplicate subscribe messages for the same ticker
8686 self ._active_subs : Dict [str , str ] = {}
87- self .config = config or {}
87+ self ._config = config or {}
8888
8989 # ------------------------------------------------------------------
9090 # Connection lifecycle
@@ -103,20 +103,42 @@ def _ensure_connected(self) -> None:
103103 "Install it with: pip install websocket-client"
104104 )
105105
106- scheme = "ws"
107- # Strip http(s):// prefix from host to build ws URL
108- host_part = self ._host
109- if host_part .startswith ("https://" ):
110- host_part = host_part [len ("https://" ):]
111- scheme = "wss"
112- elif host_part .startswith ("http://" ):
113- host_part = host_part [len ("http://" ):]
114-
115- url = f"{ scheme } ://{ host_part } /ws"
116- if self ._api_key :
117- url = f"{ url } ?apiKey={ self ._api_key } "
118- elif self ._access_token :
119- url = f"{ url } ?token={ self ._access_token } "
106+ # ✅ CHECK FOR CUSTOM WS URL FROM CONFIG
107+ custom_ws_url = self ._config .get ("wsUrl" ) if self ._config else None
108+
109+ if custom_ws_url :
110+ # Use custom WebSocket URL
111+ url = custom_ws_url
112+ # Append auth parameters if not already in URL
113+ if self ._api_key :
114+ if "?" in url :
115+ url = f"{ url } &apiKey={ self ._api_key } "
116+ else :
117+ url = f"{ url } ?apiKey={ self ._api_key } "
118+ elif self ._access_token :
119+ if "?" in url :
120+ url = f"{ url } &token={ self ._access_token } "
121+ else :
122+ url = f"{ url } ?token={ self ._access_token } "
123+ else :
124+ # Build default URL from host
125+ scheme = "ws"
126+ host_part = self ._host
127+ if host_part .startswith ("https://" ):
128+ host_part = host_part [len ("https://" ):]
129+ scheme = "wss"
130+ elif host_part .startswith ("http://" ):
131+ host_part = host_part [len ("http://" ):]
132+
133+ url = f"{ scheme } ://{ host_part } /ws"
134+ if self ._api_key :
135+ url = f"{ url } ?apiKey={ self ._api_key } "
136+ elif self ._access_token :
137+ url = f"{ url } ?token={ self ._access_token } "
138+
139+ # ✅ Get reconnect settings from config
140+ reconnect_interval = self ._config .get ("reconnectInterval" , 5000 ) if self ._config else 5000
141+ max_reconnect_attempts = self ._config .get ("maxReconnectAttempts" , 10 ) if self ._config else 10
120142
121143 last_error : Optional [Exception ] = None
122144 ws = None
@@ -133,7 +155,7 @@ def _ensure_connected(self) -> None:
133155 except Exception :
134156 pass
135157 if attempt < CONNECT_ATTEMPTS - 1 :
136- time .sleep (0.25 * ( attempt + 1 ))
158+ time .sleep (reconnect_interval / 1000.0 ) # ✅ Use reconnect_interval
137159
138160 if last_error is not None :
139161 raise last_error
0 commit comments