Skip to content

Commit bd42618

Browse files
authored
add last trade (#404)
* add last trade * fmt * correctly parse snapshot
1 parent 3e7d42b commit bd42618

File tree

4 files changed

+54
-2
lines changed

4 files changed

+54
-2
lines changed

polygon/rest/models/snapshot.py

+19
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,21 @@ def from_dict(d):
156156
return LastQuoteOptionContractSnapshot(**d)
157157

158158

159+
@modelclass
160+
class LastTradeOptionContractSnapshot:
161+
"Contains data for the most recent trade for an options contract."
162+
price: Optional[float] = None
163+
sip_timestamp: Optional[int] = None
164+
size: Optional[int] = None
165+
conditions: Optional[List[int]] = None
166+
exchange: Optional[int] = None
167+
timeframe: Optional[str] = None
168+
169+
@staticmethod
170+
def from_dict(d):
171+
return LastTradeOptionContractSnapshot(**d)
172+
173+
159174
@modelclass
160175
class Greeks:
161176
"Contains data for the greeks in an options contract."
@@ -193,6 +208,7 @@ class OptionContractSnapshot:
193208
greeks: Optional[Greeks] = None
194209
implied_volatility: Optional[float] = None
195210
last_quote: Optional[LastQuoteOptionContractSnapshot] = None
211+
last_trade: Optional[LastTradeOptionContractSnapshot] = None
196212
open_interest: Optional[float] = None
197213
underlying_asset: Optional[UnderlyingAsset] = None
198214

@@ -211,6 +227,9 @@ def from_dict(d):
211227
last_quote=None
212228
if "last_quote" not in d
213229
else LastQuoteOptionContractSnapshot.from_dict(d["last_quote"]),
230+
last_trade=None
231+
if "last_trade" not in d
232+
else LastTradeOptionContractSnapshot.from_dict(d["last_trade"]),
214233
open_interest=d.get("open_interest", None),
215234
underlying_asset=None
216235
if "underlying_asset" not in d

test_rest/mocks/v3/snapshot/options/AAPL.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@
3939
"midpoint": 29.075,
4040
"timeframe": "REAL-TIME"
4141
},
42+
"last_trade":{
43+
"price": 29.25,
44+
"sip_timestamp": 1678718527714665700,
45+
"size": 1,
46+
"conditions": [209],
47+
"exchange": 309,
48+
"timeframe": "REAL-TIME"
49+
},
4250
"open_interest": 8133,
4351
"underlying_asset": {
4452
"change_to_break_even": 19.11439999999999,
@@ -49,4 +57,4 @@
4957
}
5058
}],
5159
"status": "OK"
52-
}
60+
}

test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json

+9-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
"midpoint": 29.075,
3939
"timeframe": "REAL-TIME"
4040
},
41+
"last_trade":{
42+
"price": 29.25,
43+
"sip_timestamp": 1678718527714665700,
44+
"size": 1,
45+
"conditions": [209],
46+
"exchange": 309,
47+
"timeframe": "REAL-TIME"
48+
},
4149
"open_interest": 8133,
4250
"underlying_asset": {
4351
"change_to_break_even": 19.11439999999999,
@@ -48,4 +56,4 @@
4856
}
4957
},
5058
"status": "OK"
51-
}
59+
}

test_rest/test_snapshots.py

+17
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
OrderBookQuote,
1010
UnderlyingAsset,
1111
LastQuoteOptionContractSnapshot,
12+
LastTradeOptionContractSnapshot,
1213
Greeks,
1314
OptionDetails,
1415
DayOptionContractSnapshot,
@@ -201,6 +202,14 @@ def test_get_snapshot_option(self):
201202
midpoint=29.075,
202203
timeframe="REAL-TIME",
203204
),
205+
last_trade=LastTradeOptionContractSnapshot(
206+
price=29.25,
207+
sip_timestamp=1678718527714665700,
208+
size=1,
209+
conditions=[209],
210+
exchange=309,
211+
timeframe="REAL-TIME",
212+
),
204213
open_interest=8133,
205214
underlying_asset=UnderlyingAsset(
206215
change_to_break_even=19.11439999999999,
@@ -253,6 +262,14 @@ def test_list_snapshot_options_chain(self):
253262
midpoint=29.075,
254263
timeframe="REAL-TIME",
255264
),
265+
last_trade=LastTradeOptionContractSnapshot(
266+
price=29.25,
267+
sip_timestamp=1678718527714665700,
268+
size=1,
269+
conditions=[209],
270+
exchange=309,
271+
timeframe="REAL-TIME",
272+
),
256273
open_interest=8133,
257274
underlying_asset=UnderlyingAsset(
258275
change_to_break_even=19.11439999999999,

0 commit comments

Comments
 (0)