Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions massive/rest/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,21 @@ 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
shares_per_contract: Optional[float] = None
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):
Expand All @@ -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),
)


Expand Down
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -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"
}
94 changes: 72 additions & 22 deletions test_rest/test_contracts.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from massive.rest.models import OptionsContract
from massive.rest.models import OptionsContract, Underlying
from base import BaseTest


Expand All @@ -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",
)
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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",
),
Expand All @@ -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))
Loading