Skip to content

Commit c59334b

Browse files
committed
Updated ws example and corrected type hinting
1 parent 224ac4f commit c59334b

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

polygon/websocket/websocket_client.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ class WebSocketClient:
1717
# the same cluster and that's not desirable behavior,
1818
# somehow keeping track with multiple Client instances will be the difficulty)
1919
def __init__(self, cluster: str, auth_key: str, process_message: Optional[Callable[[str], None]] = None,
20-
on_close: Optional[Callable[[str], None]] = None, on_error: Optional[Callable[[str], None]] = None):
20+
on_close: Optional[Callable[[websocket.WebSocketApp], None]] = None,
21+
on_error: Optional[Callable[[websocket.WebSocketApp, str], None]] = None):
2122
self._host = self.DEFAULT_HOST
2223
self.url = f"wss://{self._host}/{cluster}"
2324
self.ws: websocket.WebSocketApp = websocket.WebSocketApp(self.url, on_open=self._default_on_open(),

websocket-example.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import time
22

3-
from polygon_client import WebSocketClient, STOCKS_CLUSTER
3+
from polygon import WebSocketClient, STOCKS_CLUSTER
44

55

6-
def my_customer_process_message(message):
6+
def my_custom_process_message(message):
77
print("this is my custom message processing", message)
88

99

10+
def my_custom_error_handler(ws, error):
11+
print("this is my custom error handler", error)
12+
13+
14+
def my_custom_close_handler(ws):
15+
print("this is my custom close handler")
16+
17+
1018
def main():
1119
key = 'your api key'
12-
my_client = WebSocketClient(STOCKS_CLUSTER, key, my_customer_process_message)
20+
my_client = WebSocketClient(STOCKS_CLUSTER, key, my_custom_process_message)
1321
my_client.run_async()
1422

1523
my_client.subscribe("T.MSFT", "T.AAPL", "T.AMD", "T.NVDA")

0 commit comments

Comments
 (0)