From ae03944436d81f4f80282ea6cda20dbfacc7e9d1 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Mon, 27 Nov 2023 09:34:02 -0800 Subject: [PATCH] Fix FMV ws model and added example" (#566) * Fix FMV ws model and add example * Updated example with correct tickers --- examples/websocket/fmv.py | 19 +++++++++++++++++++ polygon/websocket/models/__init__.py | 2 ++ polygon/websocket/models/models.py | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 examples/websocket/fmv.py diff --git a/examples/websocket/fmv.py b/examples/websocket/fmv.py new file mode 100644 index 00000000..5bb75f2d --- /dev/null +++ b/examples/websocket/fmv.py @@ -0,0 +1,19 @@ +from polygon import WebSocketClient +from polygon.websocket.models import WebSocketMessage, Feed, Market +from typing import List + +client = WebSocketClient(feed=Feed.Business, market=Market.Stocks, verbose=True) + +# FMV +client.subscribe("FMV.*") # all ticker symbols +# client.subscribe("FMV.TSLA") +# client.subscribe("FMV.AAPL") +# client.subscribe("FMV.NVDA") + + +def handle_msg(msgs: List[WebSocketMessage]): + for m in msgs: + print(m) + + +client.run(handle_msg) diff --git a/polygon/websocket/models/__init__.py b/polygon/websocket/models/__init__.py index fb64b6dd..06cab55d 100644 --- a/polygon/websocket/models/__init__.py +++ b/polygon/websocket/models/__init__.py @@ -35,6 +35,8 @@ def parse_single(data: Dict[str, Any]): return IndexValue.from_dict(data) elif event_type == EventType.LaunchpadValue.value: return LaunchpadValue.from_dict(data) + elif event_type == EventType.BusinessFairMarketValue.value: + return FairMarketValue.from_dict(data) return None diff --git a/polygon/websocket/models/models.py b/polygon/websocket/models/models.py index 48061e16..d6fa0c29 100644 --- a/polygon/websocket/models/models.py +++ b/polygon/websocket/models/models.py @@ -351,7 +351,7 @@ class FairMarketValue: @staticmethod def from_dict(d): - return LaunchpadValue( + return FairMarketValue( event_type=d.get("ev", None), fmv=d.get("fmv", None), ticker=d.get("sym", None), @@ -375,6 +375,7 @@ def from_dict(d): Level2Book, IndexValue, LaunchpadValue, + FairMarketValue, ] ], )