From 06e7f258fa730a85a4241b4019b5beaf6e862d22 Mon Sep 17 00:00:00 2001 From: justinpolygon <123573436+justinpolygon@users.noreply.github.com> Date: Thu, 3 Dec 2026 18:18:11 -0700 Subject: [PATCH] Add binary option fields to OptionsContract --- massive/rest/models/contracts.py | 17 +++- ...B1VDA261120C00160000&as_of=2026-11-19.json | 24 +++++ .../contracts/O;KAAPL270205C00001200.json | 29 ++++++ test_rest/test_contracts.py | 94 ++++++++++++++----- 4 files changed, 140 insertions(+), 24 deletions(-) create mode 100644 test_rest/mocks/v3/reference/options/contracts/O;B1VDA261120C00160000&as_of=2026-11-19.json create mode 100644 test_rest/mocks/v3/reference/options/contracts/O;KAAPL270205C00001200.json diff --git a/massive/rest/models/contracts.py b/massive/rest/models/contracts.py index 808943ef..f6a51838 100644 --- a/massive/rest/models/contracts.py +++ b/massive/rest/models/contracts.py @@ -22,7 +22,7 @@ class OptionsContract: additional_underlyings: Optional[List[Underlying]] = None cfi: Optional[str] = None contract_type: Optional[str] = None - correction: Optional[str] = None + correction: Optional[int] = None exercise_style: Optional[str] = None expiration_date: Optional[str] = None primary_exchange: Optional[str] = None @@ -30,6 +30,13 @@ class OptionsContract: strike_price: Optional[float] = None ticker: Optional[str] = None underlying_ticker: Optional[str] = None + type: Optional[str] = None + underlying_type: Optional[str] = None + company_ticker: Optional[str] = None + metric: Optional[str] = None + reporting_period: Optional[str] = None + report_time: Optional[str] = None + scale: Optional[int] = None @staticmethod def from_dict(d): @@ -47,9 +54,15 @@ def from_dict(d): primary_exchange=d.get("primary_exchange", None), shares_per_contract=d.get("shares_per_contract", None), strike_price=d.get("strike_price", None), - size=d.get("size", None), ticker=d.get("ticker", None), underlying_ticker=d.get("underlying_ticker", None), + type=d.get("type", None), + underlying_type=d.get("underlying_type", None), + company_ticker=d.get("company_ticker", None), + metric=d.get("metric", None), + reporting_period=d.get("reporting_period", None), + report_time=d.get("report_time", None), + scale=d.get("scale", None), ) diff --git a/test_rest/mocks/v3/reference/options/contracts/O;B1VDA261120C00160000&as_of=2026-11-19.json b/test_rest/mocks/v3/reference/options/contracts/O;B1VDA261120C00160000&as_of=2026-11-19.json new file mode 100644 index 00000000..bc3973f9 --- /dev/null +++ b/test_rest/mocks/v3/reference/options/contracts/O;B1VDA261120C00160000&as_of=2026-11-19.json @@ -0,0 +1,24 @@ +{ + "results": { + "cfi": "OCESCS", + "contract_type": "call", + "exercise_style": "european", + "expiration_date": "2026-11-20", + "primary_exchange": "XASE", + "shares_per_contract": 100, + "strike_price": 160, + "ticker": "O:B1VDA261120C00160000", + "underlying_ticker": "NVDA", + "additional_underlyings": [ + { + "type": "currency", + "underlying": "USD", + "amount": 100 + } + ], + "type": "binary", + "underlying_type": "equity" + }, + "status": "OK", + "request_id": "27137374bd4f6c6572b58f75f75e0a49" +} \ No newline at end of file diff --git a/test_rest/mocks/v3/reference/options/contracts/O;KAAPL270205C00001200.json b/test_rest/mocks/v3/reference/options/contracts/O;KAAPL270205C00001200.json new file mode 100644 index 00000000..da761711 --- /dev/null +++ b/test_rest/mocks/v3/reference/options/contracts/O;KAAPL270205C00001200.json @@ -0,0 +1,29 @@ +{ + "results": { + "cfi": "OCEMCS", + "contract_type": "call", + "exercise_style": "european", + "expiration_date": "2027-02-05", + "primary_exchange": "XCBO", + "shares_per_contract": 1, + "strike_price": 1.2, + "ticker": "O:KAAPL270205C00001200", + "underlying_ticker": "KAAPL", + "additional_underlyings": [ + { + "type": "currency", + "underlying": "USD", + "amount": 1 + } + ], + "type": "binary", + "underlying_type": "kpi", + "company_ticker": "AAPL", + "metric": "Earnings Per Share ($/share)", + "report_time": "PM", + "reporting_period": "2027Q1", + "scale": 1 + }, + "status": "OK", + "request_id": "6009e4fd73aecf2dea1b15c603e69f24" +} \ No newline at end of file diff --git a/test_rest/test_contracts.py b/test_rest/test_contracts.py index ab2ea1fb..9b50c67f 100644 --- a/test_rest/test_contracts.py +++ b/test_rest/test_contracts.py @@ -1,4 +1,4 @@ -from massive.rest.models import OptionsContract +from massive.rest.models import OptionsContract, Underlying from base import BaseTest @@ -15,7 +15,6 @@ def test_get_options_contract(self): primary_exchange="BATO", shares_per_contract=100, strike_price=2.5, - size=None, ticker="O:EVRI240119C00002500", underlying_ticker="EVRI", ) @@ -34,7 +33,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=65, - size=None, ticker="O:A220520C00065000", underlying_ticker="A", ), @@ -48,7 +46,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=70, - size=None, ticker="O:A220520C00070000", underlying_ticker="A", ), @@ -62,7 +59,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=75, - size=None, ticker="O:A220520C00075000", underlying_ticker="A", ), @@ -76,7 +72,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=80, - size=None, ticker="O:A220520C00080000", underlying_ticker="A", ), @@ -90,7 +85,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=85, - size=None, ticker="O:A220520C00085000", underlying_ticker="A", ), @@ -104,7 +98,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=90, - size=None, ticker="O:A220520C00090000", underlying_ticker="A", ), @@ -118,7 +111,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=95, - size=None, ticker="O:A220520C00095000", underlying_ticker="A", ), @@ -132,7 +124,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=100, - size=None, ticker="O:A220520C00100000", underlying_ticker="A", ), @@ -146,7 +137,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=105, - size=None, ticker="O:A220520C00105000", underlying_ticker="A", ), @@ -160,7 +150,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=110, - size=None, ticker="O:A220520C00110000", underlying_ticker="A", ), @@ -174,7 +163,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=115, - size=None, ticker="O:A220520C00115000", underlying_ticker="A", ), @@ -188,7 +176,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=120, - size=None, ticker="O:A220520C00120000", underlying_ticker="A", ), @@ -202,7 +189,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=125, - size=None, ticker="O:A220520C00125000", underlying_ticker="A", ), @@ -216,7 +202,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=130, - size=None, ticker="O:A220520C00130000", underlying_ticker="A", ), @@ -230,7 +215,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=135, - size=None, ticker="O:A220520C00135000", underlying_ticker="A", ), @@ -244,7 +228,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=140, - size=None, ticker="O:A220520C00140000", underlying_ticker="A", ), @@ -258,7 +241,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=145, - size=None, ticker="O:A220520C00145000", underlying_ticker="A", ), @@ -272,7 +254,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=150, - size=None, ticker="O:A220520C00150000", underlying_ticker="A", ), @@ -286,7 +267,6 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=155, - size=None, ticker="O:A220520C00155000", underlying_ticker="A", ), @@ -300,9 +280,79 @@ def test_list_options_contracts(self): primary_exchange="BATO", shares_per_contract=100, strike_price=160, - size=None, ticker="O:A220520C00160000", underlying_ticker="A", ), ] self.assertEqual(contracts, expected) + + def test_get_options_contract_kpi_binary(self): + contract = self.c.get_options_contract("O:KAAPL270205C00001200") + expected = OptionsContract( + additional_underlyings=[ + Underlying(amount=1, type="currency", underlying="USD") + ], + cfi="OCEMCS", + contract_type="call", + exercise_style="european", + expiration_date="2027-02-05", + primary_exchange="XCBO", + shares_per_contract=1, + strike_price=1.2, + ticker="O:KAAPL270205C00001200", + underlying_ticker="KAAPL", + type="binary", + underlying_type="kpi", + company_ticker="AAPL", + metric="Earnings Per Share ($/share)", + reporting_period="2027Q1", + report_time="PM", + scale=1, + ) + self.assertEqual(contract, expected) + self.assertEqual(contract.type, "binary") + self.assertEqual(contract.underlying_type, "kpi") + self.assertEqual(contract.company_ticker, "AAPL") + self.assertEqual(contract.metric, "Earnings Per Share ($/share)") + self.assertEqual(contract.reporting_period, "2027Q1") + self.assertEqual(contract.report_time, "PM") + self.assertEqual(contract.scale, 1) + + def test_get_options_contract_equity_binary(self): + contract = self.c.get_options_contract( + "O:B1VDA261120C00160000", as_of="2026-11-19" + ) + expected = OptionsContract( + additional_underlyings=[ + Underlying(amount=100, type="currency", underlying="USD") + ], + cfi="OCESCS", + contract_type="call", + exercise_style="european", + expiration_date="2026-11-20", + primary_exchange="XASE", + shares_per_contract=100, + strike_price=160, + ticker="O:B1VDA261120C00160000", + underlying_ticker="NVDA", + type="binary", + underlying_type="equity", + ) + self.assertEqual(contract, expected) + self.assertEqual(contract.type, "binary") + self.assertEqual(contract.underlying_type, "equity") + self.assertIsNone(contract.company_ticker) + self.assertIsNone(contract.scale) + + def test_get_options_contract_standard_has_no_binary_fields(self): + contract = self.c.get_options_contract("OEVRI240119C00002500") + for field in ( + "type", + "underlying_type", + "company_ticker", + "metric", + "reporting_period", + "report_time", + "scale", + ): + self.assertIsNone(getattr(contract, field))