From 64c590484666d8eaaf1bc6d418f32283856aba8e Mon Sep 17 00:00:00 2001 From: aitzkovitz <19159499+aitzkovitz@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:05:08 -0400 Subject: [PATCH 1/3] add last trade --- polygon/rest/models/snapshot.py | 15 +++++++++++++++ test_rest/mocks/v3/snapshot/options/AAPL.json | 10 +++++++++- .../options/AAPL/O;AAPL230616C00150000.json | 10 +++++++++- test_rest/test_snapshots.py | 17 +++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/polygon/rest/models/snapshot.py b/polygon/rest/models/snapshot.py index 676becb9..0f037d40 100644 --- a/polygon/rest/models/snapshot.py +++ b/polygon/rest/models/snapshot.py @@ -112,6 +112,20 @@ class LastQuoteOptionContractSnapshot: def from_dict(d): return LastQuoteOptionContractSnapshot(**d) +@modelclass +class LastTradeOptionContractSnapshot: + "Contains data for the most recent trade for an options contract." + price: Optional[float] = None + sip_timestamp: Optional[int] = None + size: Optional[int] = None + conditions: Optional[List[int]] = None + exchange: Optional[int] = None + timeframe: Optional[str] = None + + @staticmethod + def from_dict(d): + return LastTradeOptionContractSnapshot(**d) + @modelclass class Greeks: @@ -149,6 +163,7 @@ class OptionContractSnapshot: greeks: Optional[Greeks] = None implied_volatility: Optional[float] = None last_quote: Optional[LastQuoteOptionContractSnapshot] = None + last_trade: Optional[LastTradeOptionContractSnapshot] = None open_interest: Optional[float] = None underlying_asset: Optional[UnderlyingAsset] = None diff --git a/test_rest/mocks/v3/snapshot/options/AAPL.json b/test_rest/mocks/v3/snapshot/options/AAPL.json index 677b39ea..de91e5d7 100644 --- a/test_rest/mocks/v3/snapshot/options/AAPL.json +++ b/test_rest/mocks/v3/snapshot/options/AAPL.json @@ -39,6 +39,14 @@ "midpoint": 29.075, "timeframe": "REAL-TIME" }, + "last_trade":{ + "price": 29.25, + "sip_timestamp": 1678718527714665700, + "size": 1, + "conditions": [209], + "exchange": 309, + "timeframe": "REAL-TIME" + }, "open_interest": 8133, "underlying_asset": { "change_to_break_even": 19.11439999999999, @@ -49,4 +57,4 @@ } }], "status": "OK" -} \ No newline at end of file +} diff --git a/test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json b/test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json index da4210f8..81e4aab2 100644 --- a/test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json +++ b/test_rest/mocks/v3/snapshot/options/AAPL/O;AAPL230616C00150000.json @@ -38,6 +38,14 @@ "midpoint": 29.075, "timeframe": "REAL-TIME" }, + "last_trade":{ + "price": 29.25, + "sip_timestamp": 1678718527714665700, + "size": 1, + "conditions": [209], + "exchange": 309, + "timeframe": "REAL-TIME" + }, "open_interest": 8133, "underlying_asset": { "change_to_break_even": 19.11439999999999, @@ -48,4 +56,4 @@ } }, "status": "OK" -} \ No newline at end of file +} diff --git a/test_rest/test_snapshots.py b/test_rest/test_snapshots.py index 8051d398..6190ef6f 100644 --- a/test_rest/test_snapshots.py +++ b/test_rest/test_snapshots.py @@ -9,6 +9,7 @@ OrderBookQuote, UnderlyingAsset, LastQuoteOptionContractSnapshot, + LastTradeOptionContractSnapshot, Greeks, OptionDetails, DayOptionContractSnapshot, @@ -199,6 +200,14 @@ def test_get_snapshot_option(self): midpoint=29.075, timeframe="REAL-TIME", ), + last_trade=LastTradeOptionContractSnapshot( + price=29.25, + sip_timestamp=1678718527714665700, + size=1, + conditions=[209], + exchange=309, + timeframe="REAL-TIME", + ), open_interest=8133, underlying_asset=UnderlyingAsset( change_to_break_even=19.11439999999999, @@ -251,6 +260,14 @@ def test_list_snapshot_options_chain(self): midpoint=29.075, timeframe="REAL-TIME", ), + last_trade=LastTradeOptionContractSnapshot( + price=29.25, + sip_timestamp=1678718527714665700, + size=1, + conditions=[209], + exchange=309, + timeframe="REAL-TIME", + ), open_interest=8133, underlying_asset=UnderlyingAsset( change_to_break_even=19.11439999999999, From 207704766cf647e8086873b45cf0586a5b03d78f Mon Sep 17 00:00:00 2001 From: aitzkovitz <19159499+aitzkovitz@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:18:15 -0400 Subject: [PATCH 2/3] fmt --- polygon/rest/models/snapshot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/polygon/rest/models/snapshot.py b/polygon/rest/models/snapshot.py index 0f037d40..631e0f1c 100644 --- a/polygon/rest/models/snapshot.py +++ b/polygon/rest/models/snapshot.py @@ -112,6 +112,7 @@ class LastQuoteOptionContractSnapshot: def from_dict(d): return LastQuoteOptionContractSnapshot(**d) + @modelclass class LastTradeOptionContractSnapshot: "Contains data for the most recent trade for an options contract." From 4bf1f7a356b430109ea963957934cc2681b60a66 Mon Sep 17 00:00:00 2001 From: aitzkovitz <19159499+aitzkovitz@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:30:37 -0400 Subject: [PATCH 3/3] correctly parse snapshot --- polygon/rest/models/snapshot.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/polygon/rest/models/snapshot.py b/polygon/rest/models/snapshot.py index 631e0f1c..42826039 100644 --- a/polygon/rest/models/snapshot.py +++ b/polygon/rest/models/snapshot.py @@ -183,6 +183,9 @@ def from_dict(d): last_quote=None if "last_quote" not in d else LastQuoteOptionContractSnapshot.from_dict(d["last_quote"]), + last_trade=None + if "last_trade" not in d + else LastTradeOptionContractSnapshot.from_dict(d["last_trade"]), open_interest=d.get("open_interest", None), underlying_asset=None if "underlying_asset" not in d