Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion polygon/websocket/websocket_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class WebSocketClient:
# 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,
on_close: Optional[Callable[[str], None]] = None, on_error: Optional[Callable[[str], None]] = None):
on_close: Optional[Callable[[websocket.WebSocketApp], None]] = None,
on_error: Optional[Callable[[websocket.WebSocketApp, 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 Down
14 changes: 11 additions & 3 deletions websocket-example.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import time

from polygon_client import WebSocketClient, STOCKS_CLUSTER
from polygon import WebSocketClient, STOCKS_CLUSTER


def my_customer_process_message(message):
def my_custom_process_message(message):
print("this is my custom message processing", message)


def my_custom_error_handler(ws, error):
print("this is my custom error handler", error)


def my_custom_close_handler(ws):
print("this is my custom close handler")


def main():
key = 'your api key'
my_client = WebSocketClient(STOCKS_CLUSTER, key, my_customer_process_message)
my_client = WebSocketClient(STOCKS_CLUSTER, key, my_custom_process_message)
my_client.run_async()

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