Skip to content

Commit e9754bf

Browse files
authored
Add WS support for launchpad (#456)
* Add WS support for launchpad * update timestamp type * add launchpad example * lint
1 parent 04ea8a1 commit e9754bf

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ws.run(handle_msg=handle_msg)
8383
```
8484
Check out more detailed examples [here](https://github.com/polygon-io/client-python/tree/master/examples/websocket).
8585

86-
## Launchpad
86+
## Launchpad REST API Client
8787
Users of the Launchpad product will need to pass in certain headers in order to make API requests using the RequestOptionBuilder.
8888
Example can be found [here](./examples/launchpad).
8989

@@ -114,6 +114,23 @@ res = c.get_aggs("AAPL", 1, "day", "2022-04-04", "2022-04-04", options=options)
114114
Checkout Launchpad readme for more details on RequestOptionBuilder [here](./examples/launchpad)
115115

116116

117+
## Launchpad WebSocket Client
118+
119+
```python
120+
from polygon import WebSocketClient
121+
from polygon.websocket.models import WebSocketMessage
122+
from polygon.websocket.models.common import Feed, Market
123+
from typing import List
124+
125+
ws = WebSocketClient(api_key="API_KEY",feed=Feed.Launchpad,market=Market.Stocks, subscriptions=["AM.AAPL"])
126+
127+
def handle_msg(msg: List[WebSocketMessage]):
128+
for m in msg:
129+
print(m)
130+
131+
ws.run(handle_msg=handle_msg)
132+
```
133+
117134
## Contributing
118135

119136
If you found a bug or have an idea for a new feature, please first discuss it with us by

examples/websocket/launchpad-ws.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from polygon import WebSocketClient
2+
from polygon.websocket.models import WebSocketMessage, Feed, Market
3+
from typing import List
4+
5+
client = WebSocketClient(
6+
api_key="<POLYGON_API_KEY>", feed=Feed.Launchpad, market=Market.Stocks
7+
)
8+
9+
client.subscribe("AM.*") # all aggregates
10+
# client.subscribe("LV.*") # all aggregates
11+
# client.subscribe("AM.O:A230616C00070000") # all aggregates
12+
# client.subscribe("LV.O:A230616C00070000") # all aggregates
13+
14+
15+
def handle_msg(msgs: List[WebSocketMessage]):
16+
for m in msgs:
17+
print(m)
18+
19+
20+
# print messages
21+
client.run(handle_msg)

polygon/websocket/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ def parse_single(data: Dict[str, Any]):
2828
return Level2Book.from_dict(data)
2929
elif event_type == EventType.Value.value:
3030
return IndexValue.from_dict(data)
31+
elif event_type == EventType.LaunchpadValue.value:
32+
return LaunchpadValue.from_dict(data)
3133
return None
3234

3335

polygon/websocket/models/common.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Feed(Enum):
88
PolyFeed = "polyfeed.polygon.io"
99
PolyFeedPlus = "polyfeedplus.polygon.io"
1010
StarterFeed = "starterfeed.polygon.io"
11+
Launchpad = "launchpad.polygon.io"
1112

1213

1314
class Market(Enum):
@@ -32,3 +33,8 @@ class EventType(Enum):
3233
LimitUpLimitDown = "LULD"
3334
CryptoL2 = "XL2"
3435
Value = "V"
36+
"""Launchpad* EventTypes are only available to Launchpad users. These values are the same across all asset classes (
37+
stocks, options, forex, crypto).
38+
"""
39+
LaunchpadValue = "LV"
40+
LaunchpadAggMin = "AM"

polygon/websocket/models/models.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,23 @@ def from_dict(d):
325325
)
326326

327327

328+
@modelclass
329+
class LaunchpadValue:
330+
event_type: Optional[Union[str, EventType]] = None
331+
value: Optional[float] = None
332+
symbol: Optional[str] = None
333+
timestamp: Optional[int] = None
334+
335+
@staticmethod
336+
def from_dict(d):
337+
return LaunchpadValue(
338+
event_type=d.get("ev", None),
339+
value=d.get("val", None),
340+
symbol=d.get("sym", None),
341+
timestamp=d.get("t", None),
342+
)
343+
344+
328345
WebSocketMessage = NewType(
329346
"WebSocketMessage",
330347
List[
@@ -340,6 +357,7 @@ def from_dict(d):
340357
LimitUpLimitDown,
341358
Level2Book,
342359
IndexValue,
360+
LaunchpadValue,
343361
]
344362
],
345363
)

0 commit comments

Comments
 (0)