Skip to content

Commit 3e7d42b

Browse files
authored
restore DayOptionContractSnapshot position (#401)
1 parent 21117bd commit 3e7d42b

File tree

9 files changed

+171
-1
lines changed

9 files changed

+171
-1
lines changed

polygon/rest/models/common.py

+3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ class Market(Enum):
2121
CRYPTO = "crypto"
2222
FX = "fx"
2323
OTC = "otc"
24+
INDICES = "indices"
2425

2526

2627
class AssetClass(Enum):
2728
STOCKS = "stocks"
2829
OPTIONS = "options"
2930
CRYPTO = "crypto"
3031
FX = "fx"
32+
INDICES = "indices"
3133

3234

3335
class DividendType(Enum):
@@ -72,6 +74,7 @@ class SnapshotMarketType(Enum):
7274
STOCKS = "stocks"
7375
FOREX = "forex"
7476
CRYPTO = "crypto"
77+
INDICES = "indices"
7578

7679

7780
class Timeframe(Enum):

polygon/rest/models/markets.py

+19
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,24 @@ def from_dict(d):
2525
return MarketExchanges(**d)
2626

2727

28+
@modelclass
29+
class MarketIndices:
30+
"Contains indices market status data."
31+
s_and_p: Optional[str] = None
32+
societe_generale: Optional[str] = None
33+
msci: Optional[str] = None
34+
ftse_russell: Optional[str] = None
35+
mstar: Optional[str] = None
36+
mstarc: Optional[str] = None
37+
cccy: Optional[str] = None
38+
nasdaq: Optional[str] = None
39+
dow_jones: Optional[str] = None
40+
41+
@staticmethod
42+
def from_dict(d):
43+
return MarketIndices(**d)
44+
45+
2846
@modelclass
2947
class MarketHoliday:
3048
"MarketHoliday contains data for upcoming market holidays and their open/close times."
@@ -47,6 +65,7 @@ class MarketStatus:
4765
currencies: Optional[MarketCurrencies] = None
4866
early_hours: Optional[bool] = None
4967
exchanges: Optional[MarketExchanges] = None
68+
indicesGroups: Optional[MarketIndices] = None
5069
market: Optional[str] = None
5170
server_time: Optional[str] = None
5271

polygon/rest/models/snapshot.py

+44
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,49 @@ def from_dict(d):
3131
)
3232

3333

34+
@modelclass
35+
class IndicesSession:
36+
"Contains data for the most recent daily bar in an options contract."
37+
change: Optional[float] = None
38+
change_percent: Optional[float] = None
39+
close: Optional[float] = None
40+
high: Optional[float] = None
41+
low: Optional[float] = None
42+
open: Optional[float] = None
43+
previous_close: Optional[float] = None
44+
45+
@staticmethod
46+
def from_dict(d):
47+
return IndicesSession(**d)
48+
49+
50+
@modelclass
51+
class IndicesSnapshot:
52+
value: Optional[float] = None
53+
name: Optional[str] = None
54+
type: Optional[str] = None
55+
ticker: Optional[str] = None
56+
market_status: Optional[str] = None
57+
session: Optional[IndicesSession] = None
58+
error: Optional[str] = None
59+
message: Optional[str] = None
60+
61+
@staticmethod
62+
def from_dict(d):
63+
return IndicesSnapshot(
64+
value=d.get("value", None),
65+
name=d.get("name", None),
66+
type=d.get("type", None),
67+
ticker=d.get("ticker", None),
68+
market_status=d.get("market_status", None),
69+
session=None
70+
if "session" not in d
71+
else IndicesSession.from_dict(d["session"]),
72+
error=d.get("error", None),
73+
message=d.get("message", None),
74+
)
75+
76+
3477
@modelclass
3578
class TickerSnapshot:
3679
"Contains the most up-to-date market data for all traded ticker symbols."
@@ -132,6 +175,7 @@ class UnderlyingAsset:
132175
change_to_break_even: Optional[float] = None
133176
last_updated: Optional[int] = None
134177
price: Optional[float] = None
178+
value: Optional[float] = None
135179
ticker: Optional[str] = None
136180
timeframe: Optional[str] = None
137181

polygon/rest/models/tickers.py

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class Ticker:
6464
share_class_figi: Optional[str] = None
6565
ticker: Optional[str] = None
6666
type: Optional[str] = None
67+
source_feed: Optional[str] = None
6768

6869
@staticmethod
6970
def from_dict(d):

polygon/rest/snapshot.py

+19
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
OptionContractSnapshot,
77
SnapshotMarketType,
88
SnapshotTickerFullBook,
9+
IndicesSnapshot,
910
)
1011
from urllib3 import HTTPResponse
1112

@@ -184,3 +185,21 @@ def get_snapshot_crypto_book(
184185
raw=raw,
185186
options=options,
186187
)
188+
189+
def get_snapshot_indices(
190+
self,
191+
ticker_any_of: Optional[Union[str, List[str]]] = None,
192+
params: Optional[Dict[str, Any]] = None,
193+
raw: bool = False,
194+
options: Optional[RequestOptionBuilder] = None,
195+
) -> Union[List[IndicesSnapshot], HTTPResponse]:
196+
url = f"/v3/snapshot/indices"
197+
198+
return self._get(
199+
path=url,
200+
params=self._get_params(self.get_snapshot_indices, locals()),
201+
deserializer=IndicesSnapshot.from_dict,
202+
raw=raw,
203+
result_key="results",
204+
options=options,
205+
)

polygon/websocket/models/common.py

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Market(Enum):
1515
Options = "options"
1616
Forex = "forex"
1717
Crypto = "crypto"
18+
Indices = "indices"
1819

1920

2021
class EventType(Enum):
@@ -30,3 +31,4 @@ class EventType(Enum):
3031
Imbalances = "NOI"
3132
LimitUpLimitDown = "LULD"
3233
CryptoL2 = "XL2"
34+
Value = "V"

polygon/websocket/models/models.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
@modelclass
77
class EquityAgg:
8-
"EquityAgg contains aggregate data for either stock tickers or option contracts."
8+
"""EquityAgg contains aggregate data for either stock tickers, option contracts or index tickers."""
9+
910
event_type: Optional[Union[str, EventType]] = None
1011
symbol: Optional[str] = None
1112
volume: Optional[float] = None
@@ -307,6 +308,21 @@ def from_dict(d):
307308
)
308309

309310

311+
@modelclass
312+
class IndexValue:
313+
event_type: Optional[Union[str, EventType]] = None
314+
value: Optional[float] = None
315+
ticker: Optional[str] = None
316+
timestamp: Optional[str] = None
317+
318+
@staticmethod
319+
def from_dict(d):
320+
d.get("ev", None),
321+
d.get("val", None),
322+
d.get("T", None),
323+
d.get("t", None)
324+
325+
310326
WebSocketMessage = NewType(
311327
"WebSocketMessage",
312328
List[
@@ -321,6 +337,7 @@ def from_dict(d):
321337
Imbalance,
322338
LimitUpLimitDown,
323339
Level2Book,
340+
IndexValue,
324341
]
325342
],
326343
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"results": [
3+
{
4+
"value": 3822.39,
5+
"name": "S&P 500",
6+
"ticker": "SPX",
7+
"type": "indices",
8+
"market_status": "closed",
9+
"session": {
10+
"change": -50.01,
11+
"change_percent": -1.45,
12+
"close": 3822.39,
13+
"high": 3834.41,
14+
"low": 38217.11,
15+
"open": 3827.38,
16+
"previous_close": 3812.19
17+
}
18+
},
19+
{
20+
"ticker": "APx",
21+
"error": "NOT_FOUND",
22+
"message": "Ticker not found."
23+
},
24+
{
25+
"ticker": "APy",
26+
"error": "NOT_ENTITLED",
27+
"message": "Not entitled to this ticker."
28+
}
29+
]
30+
}

test_rest/test_snapshots.py

+35
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
Greeks,
1313
OptionDetails,
1414
DayOptionContractSnapshot,
15+
IndicesSnapshot,
16+
IndicesSession,
1517
)
1618
from base import BaseTest
1719

@@ -283,3 +285,36 @@ def test_get_snapshot_crypto_book(self):
283285
updated=1605295074162,
284286
)
285287
self.assertEqual(snapshots, expected)
288+
289+
def test_get_snapshot_indices(self):
290+
ticker_any_of = ["SPX", "APx", "APy"]
291+
summary_results = self.c.get_snapshot_indices(ticker_any_of)
292+
expected = [
293+
IndicesSnapshot(
294+
value=3822.39,
295+
name="S&P 500",
296+
type="indices",
297+
ticker="SPX",
298+
market_status="closed",
299+
session=IndicesSession(
300+
change=-50.01,
301+
change_percent=-1.45,
302+
close=3822.39,
303+
high=3834.41,
304+
low=38217.11,
305+
open=3827.38,
306+
previous_close=3812.19,
307+
),
308+
),
309+
IndicesSnapshot(
310+
ticker="APx",
311+
message="Ticker not found.",
312+
error="NOT_FOUND",
313+
),
314+
IndicesSnapshot(
315+
ticker="APy",
316+
error="NOT_ENTITLED",
317+
message="Not entitled to this ticker.",
318+
),
319+
]
320+
self.assertEqual(summary_results, expected)

0 commit comments

Comments
 (0)