feat: add options exposure summary command#7540
Closed
HOYALIM wants to merge 1 commit into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a new options “exposure” endpoint that aggregates options chain exposures (OI/volume plus DEX/GEX when available) by strike or expiration, and introduces integration coverage for both Python and HTTP API usage.
Changes:
- Added helpers to normalize options chain inputs and compute exposure aggregates + summary metrics.
- Added
POST /derivatives/options/exposurerouter command with filtering controls (ITM/OTM, DTE, moneyness, strike range, etc.). - Added integration tests for the new exposure command via the Python client and via the REST API.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py | Adds exposure aggregation helpers and the new exposure router command. |
| openbb_platform/extensions/derivatives/integration/test_derivatives_python.py | Adds Python integration test validating exposure aggregation on synthetic chain data. |
| openbb_platform/extensions/derivatives/integration/test_derivatives_api.py | Adds REST API integration test hitting the new exposure endpoint with synthetic data. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+29
to
+34
| if isinstance(data, OptionsChainsData): | ||
| df = DataFrame(data.model_dump(exclude_none=True, exclude_unset=True)) | ||
| elif isinstance(data, DataFrame): | ||
| df = DataFrame(data.copy()) | ||
| elif isinstance(data, dict): | ||
| df = DataFrame(data if all(isinstance(v, list) for v in data.values()) else [data]) |
Comment on lines
+24
to
+25
| def _options_data_to_df(data: list[Data] | Data, underlying_price: float | None = None): | ||
| """Normalize options chain inputs into a DataFrame.""" |
Comment on lines
+469
to
+482
| @router.command( | ||
| methods=["POST"], | ||
| examples=[ | ||
| PythonEx( | ||
| description="Summarize gamma, delta, open interest, and volume exposure by strike.", | ||
| code=[ | ||
| "data = obb.derivatives.options.chains('AAPL', provider='cboe')", | ||
| "exposure = obb.derivatives.options.exposure(data=data.results, by='strike')", | ||
| "exposure.to_df(index=None).head()", | ||
| "exposure.extra['summary']", | ||
| ], | ||
| ), | ||
| ], | ||
| ) |
Comment on lines
+133
to
+144
| def _as_native(value: Any) -> Any: | ||
| """Convert Pandas/Numpy values to API-safe Python values.""" | ||
| # pylint: disable=import-outside-toplevel | ||
| from pandas import isna | ||
|
|
||
| if isna(value): | ||
| return None | ||
| if hasattr(value, "item"): | ||
| return value.item() | ||
| if hasattr(value, "date"): | ||
| return value.date().isoformat() | ||
| return value |
Comment on lines
+9
to
+20
| SYNTHETIC_OPTIONS_CHAIN = [ | ||
| { | ||
| "expiration": "2030-01-17", | ||
| "strike": 100, | ||
| "option_type": "call", | ||
| "open_interest": 10, | ||
| "volume": 5, | ||
| "delta": 0.6, | ||
| "gamma": 0.02, | ||
| "underlying_price": 100, | ||
| "contract_size": 100, | ||
| }, |
Comment on lines
+314
to
+319
| result = requests.post( | ||
| url, | ||
| headers=headers, | ||
| timeout=10, | ||
| data=json.dumps({"data": SYNTHETIC_OPTIONS_CHAIN}), | ||
| ) |
a9c91e8 to
ee5f3b7
Compare
ee5f3b7 to
09e64f5
Compare
Contributor
|
This is a sloppy duplication of code that already exists. No AI slop please. >>> chains = obb.derivatives.options.chains("AAPL", provider="cboe").results
>>> chains.filter_data(by="expiration", stat="gex")
Expiration Calls Puts Total Net Percent PCR
0 2026-06-17 214090503 273214326 487304829 13.1106 1.2762
1 2026-06-18 680939740 314556408 995496148 26.7830 0.4619
2 2026-06-22 38516758 24226907 62743665 1.6881 0.6290
3 2026-06-24 11141622 7413023 18554645 0.4992 0.6653
4 2026-06-26 101525600 43103941 144629541 3.8911 0.4246
5 2026-06-29 5524176 1304785 6828961 0.1837 0.2362
6 2026-07-02 43041360 19692821 62734181 1.6878 0.4575
7 2026-07-10 23114116 10716690 33830806 0.9102 0.4636
8 2026-07-17 451401437 145964630 597366067 16.0717 0.3234
9 2026-07-24 12392113 4803901 17196014 0.4626 0.3877
10 2026-07-31 3504463 2360221 5864684 0.1578 0.6735
11 2026-08-21 197663794 86333364 283997158 7.6407 0.4368
12 2026-09-18 197227202 64005320 261232522 7.0283 0.3245
13 2026-10-16 45612405 25137026 70749431 1.9035 0.5511
14 2026-11-20 33031872 25342215 58374087 1.5705 0.7672
15 2026-12-18 94294502 55901629 150196131 4.0409 0.5928
16 2027-01-15 174550211 95371423 269921634 7.2620 0.5464
17 2027-02-19 4230719 5830496 10061215 0.2707 1.3781
18 2027-03-19 16951943 8713374 25665317 0.6905 0.5140
19 2027-06-17 36449102 18806267 55255369 1.4866 0.5160
20 2027-09-17 4019041 2101534 6120575 0.1647 0.5229
21 2027-12-17 21150626 13545057 34695683 0.9335 0.6404
22 2028-01-21 24390774 10503889 34894663 0.9388 0.4307
23 2028-03-17 4779062 2564972 7344034 0.1976 0.5367
24 2028-12-15 11172100 4660291 15832391 0.4260 0.4171 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
obb.derivatives.options.exposurefor option-chain exposure summariesnet_dex/net_gexseparately from grosstotal_dex/total_gexQuality Hardening
OptionsChainsData.last_pricewhen users set the underlying price after fetching chainseod_datefor historical option-chain rows before falling back to todaylast_price, and historical DTE handlingTests
uvx --from black black --check openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py openbb_platform/extensions/derivatives/openbb_derivatives/options/helpers.py openbb_platform/extensions/derivatives/tests/test_options_exposure.py openbb_platform/extensions/derivatives/integration/test_derivatives_python.py openbb_platform/extensions/derivatives/integration/test_derivatives_api.pyuvx --from ruff ruff check openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py openbb_platform/extensions/derivatives/openbb_derivatives/options/helpers.py openbb_platform/extensions/derivatives/tests/test_options_exposure.py openbb_platform/extensions/derivatives/integration/test_derivatives_python.py openbb_platform/extensions/derivatives/integration/test_derivatives_api.pyuvx --from openbb-devtools mypy openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py openbb_platform/extensions/derivatives/openbb_derivatives/options/helpers.py --ignore-missing-imports --scripts-are-modules --check-untyped-defsuvx --from openbb-devtools pylint openbb_platform/extensions/derivatives/openbb_derivatives/options/options_router.py openbb_platform/extensions/derivatives/openbb_derivatives/options/helpers.pyPYTHONPATH=openbb_platform/core:openbb_platform/extensions/derivatives uvx --from pytest --with pandas --with pydantic --with uuid7 --with fastapi --with python-multipart --with requests --with aiohttp --with websockets --with html5lib --with python-dotenv --with importlib-metadata --with pyjwt pytest openbb_platform/extensions/derivatives/tests/test_options_exposure.py -qPYTHONPATH=<core plus all extension package dirs> uvx --from pytest --with pandas --with pydantic --with uuid7 --with fastapi --with python-multipart --with requests --with aiohttp --with websockets --with html5lib --with python-dotenv --with importlib-metadata --with pyjwt pytest openbb_platform/extensions/tests/test_routers.py -qRefs #6948