Skip to content

Commit 0b86ae7

Browse files
Add indices.py ws example (#429)
Adding a example Indices example that works for streaming both aggregates and values.
1 parent d271e44 commit 0b86ae7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

examples/websocket/indices.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from polygon import WebSocketClient
2+
from polygon.websocket.models import WebSocketMessage, Market
3+
from typing import List
4+
5+
client = WebSocketClient(market=Market.Indices)
6+
7+
# aggregates (per minute)
8+
# client.subscribe("AM.*") # all aggregates
9+
client.subscribe("AM.I:SPX") # Standard & Poor's 500
10+
client.subscribe("AM.I:DJI") # Dow Jones Industrial Average
11+
client.subscribe("AM.I:NDX") # Nasdaq-100
12+
client.subscribe("AM.I:VIX") # Volatility Index
13+
14+
# single index
15+
# client.subscribe("V.*") # all tickers
16+
# client.subscribe("V.I:SPX") # Standard & Poor's 500
17+
# client.subscribe("V.I:DJI") # Dow Jones Industrial Average
18+
# client.subscribe("V.I:NDX") # Nasdaq-100
19+
# client.subscribe("V.I:VIX") # Volatility Index
20+
21+
22+
def handle_msg(msgs: List[WebSocketMessage]):
23+
for m in msgs:
24+
print(m)
25+
26+
27+
client.run(handle_msg)

0 commit comments

Comments
 (0)