Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion polygon/websocket/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class WebSocketClient:
# the 3 possible clusters (I think I like client per, but then a problem is the user can make multiple clients for
# the same cluster and that's not desirable behavior,
# somehow keeping track with multiple Client instances will be the difficulty)
def __init__(self, cluster: str, auth_key: str, process_message: Optional[Callable[[str], None]] = None):
def __init__(self, cluster: str, auth_key: str, process_message: Optional[Callable[[str], None]] = None,
on_close: Optional[Callable[[str], None]] = None, on_error: Optional[Callable[[str], None]] = None):
self._host = self.DEFAULT_HOST
self.url = f"wss://{self._host}/{cluster}"
self.ws: websocket.WebSocketApp = websocket.WebSocketApp(self.url, on_open=self._default_on_open(),
Expand All @@ -26,6 +27,8 @@ def __init__(self, cluster: str, auth_key: str, process_message: Optional[Callab
self.auth_key = auth_key

self.process_message = process_message
self.ws.on_close = on_close
self.ws.on_error = on_error

# being authenticated is an event that must occur before any other action is sent to the server
self._authenticated = threading.Event()
Expand Down