Skip to content

Commit e3f0547

Browse files
Add crypto, forex and indices agg sec examples (#557)
* Add Forex and Indices Agg Sec examples * Update crypto example * Fix lint
1 parent e65bf51 commit e3f0547

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

examples/websocket/crypto.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,42 @@
22
from polygon.websocket.models import WebSocketMessage, Market
33
from typing import List
44

5-
c = WebSocketClient(market=Market.Crypto, subscriptions=["XA.*"])
5+
client = WebSocketClient(market=Market.Crypto)
6+
7+
# Aggregates (per minute)
8+
client.subscribe("XA.*") # all crypto pair
9+
# client.subscribe("XA.BTC-USD")
10+
# client.subscribe("XA.BTC-EUR")
11+
# client.subscribe("XA.ETH-USD")
12+
13+
# Aggregates (per second)
14+
# client.subscribe("XAS.*") # all crypto pair
15+
# client.subscribe("XAS.BTC-USD")
16+
# client.subscribe("XAS.BTC-EUR")
17+
# client.subscribe("XAS.ETH-USD")
18+
19+
# Trades
20+
# client.subscribe("XT.*") # all crypto pair
21+
# client.subscribe("XT.BTC-USD")
22+
# client.subscribe("XT.BTC-EUR")
23+
# client.subscribe("XT.ETH-USD")
24+
25+
# Quotes
26+
# client.subscribe("XQ.*") # all crypto pair
27+
# client.subscribe("XQ.BTC-USD")
28+
# client.subscribe("XQ.BTC-EUR")
29+
# client.subscribe("XQ.ETH-USD")
30+
31+
# Level 2 Book
32+
# client.subscribe("XL2.*") # all crypto pair
33+
# client.subscribe("XL2.BTC-USD")
34+
# client.subscribe("XL2.BTC-EUR")
35+
# client.subscribe("XL2.ETH-USD")
636

737

838
def handle_msg(msgs: List[WebSocketMessage]):
939
for m in msgs:
1040
print(m)
1141

1242

13-
c.run(handle_msg)
43+
client.run(handle_msg)

examples/websocket/forex.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from polygon import WebSocketClient
2+
from polygon.websocket.models import WebSocketMessage, Market
3+
from typing import List
4+
5+
client = WebSocketClient(market=Market.Forex)
6+
7+
# Aggregates (per minute)
8+
# client.subscribe("CA.*") # all forex pair
9+
client.subscribe("CA.USD/CAD")
10+
client.subscribe("CA.USD/EUR")
11+
client.subscribe("CA.USD/AUD")
12+
13+
# Aggregates (per second)
14+
# client.subscribe("CAS.*") # all forex pair
15+
# client.subscribe("CAS.USD/CAD")
16+
# client.subscribe("CAS.USD/EUR")
17+
# client.subscribe("CAS.USD/AUD")
18+
19+
# Quotes
20+
# client.subscribe("C.*") # all forex pair
21+
# client.subscribe("C.USD/CAD")
22+
# client.subscribe("C.USD/EUR")
23+
# client.subscribe("C.USD/AUD")
24+
25+
26+
def handle_msg(msgs: List[WebSocketMessage]):
27+
for m in msgs:
28+
print(m)
29+
30+
31+
client.run(handle_msg)

examples/websocket/indices.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@
44

55
client = WebSocketClient(market=Market.Indices)
66

7-
# aggregates (per minute)
7+
# Aggregates (per minute)
88
# client.subscribe("AM.*") # all aggregates
99
client.subscribe("AM.I:SPX") # Standard & Poor's 500
1010
client.subscribe("AM.I:DJI") # Dow Jones Industrial Average
1111
client.subscribe("AM.I:NDX") # Nasdaq-100
1212
client.subscribe("AM.I:VIX") # Volatility Index
1313

14-
# single index
14+
# Aggregates (per second)
15+
# client.subscribe("A.*") # all aggregates
16+
# client.subscribe("A.I:SPX") # Standard & Poor's 500
17+
# client.subscribe("A.I:DJI") # Dow Jones Industrial Average
18+
# client.subscribe("A.I:NDX") # Nasdaq-100
19+
# client.subscribe("A.I:VIX") # Volatility Index
20+
21+
# Single index
1522
# client.subscribe("V.*") # all tickers
1623
# client.subscribe("V.I:SPX") # Standard & Poor's 500
1724
# client.subscribe("V.I:DJI") # Dow Jones Industrial Average

0 commit comments

Comments
 (0)