summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanglewood <85772166+deeleeramone@users.noreply.github.com>2024-06-15 21:41:30 -0700
committerDanglewood <85772166+deeleeramone@users.noreply.github.com>2024-06-15 21:41:30 -0700
commit43dfeae1f87016e0d5af9c9f5ce91fa682126f1e (patch)
tree6c414acca7cf2891ec64a84ff934c8c862e25938
parentacec71ba2d17a04440a8db403cb92cb5f9b8f305 (diff)
options snapshots
-rw-r--r--openbb_platform/core/openbb_core/provider/standard_models/options_snapshots.py75
-rw-r--r--openbb_platform/extensions/derivatives/integration/test_derivatives_api.py18
-rw-r--r--openbb_platform/extensions/derivatives/integration/test_derivatives_python.py15
-rw-r--r--openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py18
-rw-r--r--openbb_platform/openbb/assets/reference.json289
-rw-r--r--openbb_platform/openbb/package/derivatives_options.py116
6 files changed, 531 insertions, 0 deletions
diff --git a/openbb_platform/core/openbb_core/provider/standard_models/options_snapshots.py b/openbb_platform/core/openbb_core/provider/standard_models/options_snapshots.py
new file mode 100644
index 00000000000..9149a9b4bab
--- /dev/null
+++ b/openbb_platform/core/openbb_core/provider/standard_models/options_snapshots.py
@@ -0,0 +1,75 @@
+"""Options Snapshots Standard Model."""
+
+from datetime import (
+ date as dateType,
+ datetime,
+)
+from typing import Literal, Optional
+
+from pydantic import Field
+
+from openbb_core.provider.abstract.data import Data
+from openbb_core.provider.abstract.query_params import QueryParams
+from openbb_core.provider.utils.descriptions import DATA_DESCRIPTIONS
+
+
+class OptionsSnapshotsQueryParams(QueryParams):
+ """Options Snapshots Query."""
+
+
+class OptionsSnapshotsData(Data):
+ """Options Snapshots Data."""
+
+ underlying_symbol: str = Field(description="Ticker symbol of the underlying asset.")
+ contract_symbol: str = Field(description="Symbol of the options contract.")
+ expiration: dateType = Field(description="Expiration date of the options contract.")
+ dte: Optional[int] = Field(
+ default=None,
+ description="Number of days to expiration of the options contract.",
+ )
+ strike: float = Field(
+ description="Strike price of the options contract.",
+ json_schema_extra={"x-unit_measurement": "currency"},
+ )
+ option_type: str = Field(description="The type of option.")
+ volume: Optional[int] = Field(
+ default=None,
+ description="Total trade volume from the beginning of the session.",
+ )
+ open_interest: Optional[int] = Field(
+ default=None,
+ description="Open interest at the time.",
+ )
+ last_price: Optional[float] = Field(
+ default=None,
+ description="Last trade price at the time.",
+ json_schema_extra={"x-unit_measurement": "currency"},
+ )
+ last_size: Optional[int] = Field(
+ default=None,
+ description="Lot size of the last trade.",
+ )
+ last_timestamp: Optional[datetime] = Field(
+ default=None,
+ description="Timestamp of the last price.",
+ )
+ open: Optional[float] = Field(
+ default=None,
+ description=DATA_DESCRIPTIONS.get("open", ""),
+ json_schema_extra={"x-unit_measurement": "currency"},
+ )
+ high: Optional[float] = Field(
+ default=None,
+ description=DATA_DESCRIPTIONS.get("high", ""),
+ json_schema_extra={"x-unit_measurement": "currency"},
+ )
+ low: Optional[float] = Field(
+ default=None,
+ description=DATA_DESCRIPTIONS.get("low", ""),
+ json_schema_extra={"x-unit_measurement": "currency"},
+ )
+ close: Optional[float] = Field(
+ default=None,
+ description=DATA_DESCRIPTIONS.get("close", ""),
+ json_schema_extra={"x-unit_measurement": "currency"},
+ )
diff --git a/openbb_platform/extensions/derivatives/integration/test_derivatives_api.py b/openbb_platform/extensions/derivatives/integration/test_derivatives_api.py
index 23089fe9f1b..97e9a3551eb 100644
--- a/openbb_platform/extensions/derivatives/integration/test_derivatives_api.py
+++ b/openbb_platform/extensions/derivatives/integration/test_derivatives_api.py
@@ -142,3 +142,21 @@ def test_derivatives_futures_curve(params, headers):
result = requests.get(url, headers=headers, timeout=60)
assert isinstance(result, requests.Response)
assert result.status_code == 200
+
+
+@parametrize(
+ "params",
+ [
+ ({"provider": "intrinio", "date": None, "only_traded": True}),
+ ],
+)
+@pytest.mark.integration
+def test_derivatives_options_snapshots(params, headers):
+ """Test the options snapshots endpoint."""
+ params = {p: v for p, v in params.items() if v}
+
+ query_str = get_querystring(params, [])
+ url = f"http://0.0.0.0:8000/api/v1/derivatives/options/snapshots?{query_str}"
+ result = requests.get(url, headers=headers, timeout=60)
+ assert isinstance(result, requests.Response)
+ assert result.status_code == 200
diff --git a/openbb_platform/extensions/derivatives/integration/test_derivatives_python.py b/openbb_platform/extensions/derivatives/integration/test_derivatives_python.py
index c03cc32d6a7..4e04039bc7a 100644
--- a/openbb_platform/extensions/derivatives/integration/test_derivatives_python.py
+++ b/openbb_platform/extensions/derivatives/integration/test_derivatives_python.py
@@ -126,3 +126,18 @@ def test_derivatives_futures_curve(params, obb):
assert result
assert isinstance(result, OBBject)
assert len(result.results) > 0
+
+
+@parametrize(
+ "params",
+ [
+ ({"provider": "intrinio", "date": None, "only_traded": True}),
+ ],
+)
+@pytest.mark.integration
+def test_derivatives_options_snapshots(params, obb):
+ """Test the options snapshots endpoint."""
+ result = obb.derivatives.options.snapshots(**params)
+ assert result
+ assert isinstance(result, OBBject)
+ assert len(result.results) > 0
diff --git a/openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py b/openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py
index dbed2aa674d..bcdb00be4b7 100644
--- a/openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py
+++ b/openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py
@@ -54,3 +54,21 @@ async def unusual(
) -> OBBject:
"""Get the complete options chain for a ticker."""
return await OBBject.from_query(Query(**locals()))
+
+
+@router.command(
+ model="OptionsSnapshots",
+ examples=[
+ APIEx(
+ parameters={"provider": "intrinio"},
+ ),
+ ],
+)
+async def snapshots(
+ cc: CommandContext,
+ provider_choices: ProviderChoices,
+ standard_params: StandardParams,
+ extra_params: ExtraParams,
+) -> OBBject:
+ """Get a snapshot of the options market universe."""
+ return await OBBject.from_query(Query(**locals()))
diff --git a/openbb_platform/openbb/assets/reference.json b/openbb_platform/openbb/assets/reference.json
index 796ed92303d..4fc15862c20 100644
--- a/openbb_platform/openbb/assets/reference.json
+++ b/openbb_platform/openbb/assets/reference.json
@@ -1991,6 +1991,295 @@
},
"model": "OptionsUnusual"
},
+ "/derivatives/options/snapshots": {
+ "deprecated": {
+ "flag": null,
+ "message": null
+ },
+ "description": "Get a snapshot of the options market universe.",
+ "examples": "\nExamples\n--------\n\n```python\nfrom openbb import obb\nobb.derivatives.options.snapshots(provider='intrinio')\n```\n\n",
+ "parameters": {
+ "standard": [
+ {
+ "name": "provider",
+ "type": "Literal['intrinio']",
+ "description": "The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: i, n, t, r, i, n, i, o.",
+ "default": null,
+ "optional": true
+ }
+ ],
+ "intrinio": [
+ {
+ "name": "date",
+ "type": "Union[Union[date, datetime, str], str]",
+ "description": "The date of the data. Can be a datetime or an ISO datetime string. Data appears to go back to around 2022-06-01 Example: '2024-03-08T12:15:00+0400'",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "only_traded",
+ "type": "bool",
+ "description": "Only include options that have been traded during the session, default is True. Setting to false will dramatically increase the size of the response - use with caution.",
+ "default": true,
+ "optional": true,
+ "choices": null
+ }
+ ]
+ },
+ "returns": {
+ "OBBject": [
+ {
+ "name": "results",
+ "type": "List[OptionsSnapshots]",
+ "description": "Serializable results."
+ },
+ {
+ "name": "provider",
+ "type": "Optional[Literal['intrinio']]",
+ "description": "Provider name."
+ },
+ {
+ "name": "warnings",
+ "type": "Optional[List[Warning_]]",
+ "description": "List of warnings."
+ },
+ {
+ "name": "chart",
+ "type": "Optional[Chart]",
+ "description": "Chart object."
+ },
+ {
+ "name": "extra",
+ "type": "Dict[str, Any]",
+ "description": "Extra info."
+ }
+ ]
+ },
+ "data": {
+ "standard": [
+ {
+ "name": "underlying_symbol",
+ "type": "str",
+ "description": "Ticker symbol of the underlying asset.",
+ "default": "",
+ "optional": false,
+ "choices": null
+ },
+ {
+ "name": "contract_symbol",
+ "type": "str",
+ "description": "Symbol of the options contract.",
+ "default": "",
+ "optional": false,
+ "choices": null
+ },
+ {
+ "name": "expiration",
+ "type": "date",
+ "description": "Expiration date of the options contract.",
+ "default": "",
+ "optional": false,
+ "choices": null
+ },
+ {
+ "name": "dte",
+ "type": "int",
+ "description": "Number of days to expiration of the options contract.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "strike",
+ "type": "float",
+ "description": "Strike price of the options contract.",
+ "default": "",
+ "optional": false,
+ "choices": null
+ },
+ {
+ "name": "option_type",
+ "type": "str",
+ "description": "The type of option.",
+ "default": "",
+ "optional": false,
+ "choices": null
+ },
+ {
+ "name": "volume",
+ "type": "int",
+ "description": "Total trade volume from the beginning of the session.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "open_interest",
+ "type": "int",
+ "description": "Open interest at the time.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "last_price",
+ "type": "float",
+ "description": "Last trade price at the time.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "last_size",
+ "type": "int",
+ "description": "Lot size of the last trade.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "last_timestamp",
+ "type": "datetime",
+ "description": "Timestamp of the last price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "open",
+ "type": "float",
+ "description": "The open price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "high",
+ "type": "float",
+ "description": "The high price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "low",
+ "type": "float",
+ "description": "The low price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "close",
+ "type": "float",
+ "description": "The close price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ }
+ ],
+ "intrinio": [
+ {
+ "name": "bid",
+ "type": "float",
+ "description": "The last bid price at the time.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "bid_size",
+ "type": "int",
+ "description": "The size of the last bid price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "bid_timestamp",
+ "type": "datetime",
+ "description": "The timestamp of the last bid price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "ask",
+ "type": "float",
+ "description": "The last ask price at the time.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "ask_size",
+ "type": "int",
+ "description": "The size of the last ask price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "ask_timestamp",
+ "type": "datetime",
+ "description": "The timestamp of the last ask price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "total_bid_volume",
+ "type": "int",
+ "description": "Total volume of bids.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "bid_high",
+ "type": "float",
+ "description": "The highest bid price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "bid_low",
+ "type": "float",
+ "description": "The lowest bid price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "total_ask_volume",
+ "type": "int",
+ "description": "Total volume of asks.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "ask_high",
+ "type": "float",
+ "description": "The highest ask price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ },
+ {
+ "name": "ask_low",
+ "type": "float",
+ "description": "The lowest ask price.",
+ "default": null,
+ "optional": true,
+ "choices": null
+ }
+ ]
+ },
+ "model": "OptionsSnapshots"
+ },
"/derivatives/futures/historical": {
"deprecated": {
"flag": null,
diff --git a/openbb_platform/openbb/package/derivatives_options.py b/openbb_platform/openbb/package/derivatives_options.py
index cc7bea84974..8ee07ea3a21 100644
--- a/openbb_platform/openbb/package/derivatives_options.py
+++ b/openbb_platform/openbb/package/derivatives_options.py
@@ -13,6 +13,7 @@ from typing_extensions import Annotated
class ROUTER_derivatives_options(Container):
"""/derivatives/options
chains
+ snapshots
unusual
"""
@@ -215,6 +216,121 @@ class ROUTER_derivatives_options(Container):
@exception_handler
@validate
+ def snapshots(
+ self,
+ provider: Annotated[
+ Optional[Literal["intrinio"]],
+ OpenBBField(
+ description="The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: intrinio."
+ ),
+ ] = None,
+ **kwargs
+ ) -> OBBject:
+ """Get a snapshot of the options market universe.
+
+ Parameters
+ ----------
+ provider : Optional[Literal['intrinio']]
+ The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: intrinio.
+ date : Optional[Union[datetime.date, datetime.datetime, str]]
+ The date of the data. Can be a datetime or an ISO datetime string. Data appears to go back to around 2022-06-01 Example: '2024-03-08T12:15:00+0400' (provider: intrinio)
+ only_traded : bool
+ Only include options that have been traded during the session, default is True. Setting to false will dramatically increase the size of the response - use with caution. (provider: intrinio)
+
+ Returns
+ -------
+ OBBject
+ results : List[OptionsSnapshots]
+ Serializable results.
+ provider : Optional[Literal['intrinio']]
+ Provider name.
+ warnings : Optional[List[Warning_]]
+ List of warnings.
+ chart : Optional[Chart]
+ Chart object.
+ extra : Dict[str, Any]
+ Extra info.
+
+ OptionsSnapshots
+ ----------------
+ underlying_symbol : str
+ Ticker symbol of the underlying asset.
+ contract_symbol : str
+ Symbol of the options contract.
+ expiration : date
+ Expiration date of the options contract.
+ dte : Optional[int]
+ Number of days to expiration of the options contract.
+ strike : float
+ Strike price of the options contract.
+ option_type : str
+ The type of option.
+ volume : Optional[int]
+ Total trade volume from the beginning of the session.
+ open_interest : Optional[int]
+ Open interest at the time.
+ last_price : Optional[float]
+ Last trade price at the time.
+ last_size : Optional[int]
+ Lot size of the last trade.
+ last_timestamp : Optional[datetime]
+ Timestamp of the last price.
+ open : Optional[float]
+ The open price.
+ high : Optional[float]
+ The high price.
+ low : Optional[float]
+ The low price.
+ close : Optional[float]
+ The close price.
+ bid : Optional[float]
+ The last bid price at the time. (provider: intrinio)
+ bid_size : Optional[int]
+ The size of the last bid price. (provider: intrinio)
+ bid_timestamp : Optional[datetime]
+ The timestamp of the last bid price. (provider: intrinio)
+ ask : Optional[float]
+ The last ask price at the time. (provider: intrinio)
+ ask_size : Optional[int]
+ The size of the last ask price. (provider: intrinio)
+ ask_timestamp : Optional[datetime]
+ The timestamp of the last ask price. (provider: intrinio)
+ total_bid_volume : Optional[int]
+ Total volume of bids. (provider: intrinio)
+ bid_high : Optional[float]
+ The highest bid price. (provider: intrinio)
+ bid_low : Optional[float]
+ The lowest bid price. (provider: intrinio)
+ total_ask_volume : Optional[int]
+ Total volume of asks. (provider: intrinio)
+ ask_high : Optional[float]
+ The highest ask price. (provider: intrinio)
+ ask_low : Optional[float]
+ The lowest ask price. (provider: intrinio)
+
+ Examples
+ --------
+ >>> from openbb import obb
+ >>> obb.derivatives.options.snapshots(provider='intrinio')
+ """ # noqa: E501
+
+ return self._run(
+ "/derivatives/options/snapshots",
+ **filter_inputs(
+ provider_choices={
+ "provider": self._get_provider(
+ provider,
+ "derivatives.options.snapshots",
+ ("intrinio",),
+ )
+ },
+ standard_params={},
+ extra_params=kwargs,
+ )
+ )
+
+ @exception_handler
+ @validate
def unusual(
self,
symbol: Annotated[