diff options
author | James Maslek <jmaslek11@gmail.com> | 2024-11-04 21:57:30 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-05 02:57:30 +0000 |
commit | 64e0a235820d241b8a6fc7ba5ba77a1903367678 (patch) | |
tree | f2d810e1635e98569df0a9eeebdfe474de5d6249 | |
parent | 0c303026508a63365b44ce39173e0785b1ff4752 (diff) |
Intrinio realtime (delayed) options (#6931)
* remove ultima + althub
* move twitter keys
* Small edits to allow realtime/delayed intrinio options
* update tests
* static files and fix date validator
* expose the data collecting tasks to Unauthorized Error
---------
Co-authored-by: Danglewood <85772166+deeleeramone@users.noreply.github.com>
8 files changed, 4810 insertions, 14461 deletions
diff --git a/openbb_platform/extensions/derivatives/integration/test_derivatives_api.py b/openbb_platform/extensions/derivatives/integration/test_derivatives_api.py index bc753851c3b..4dc7e1309a0 100644 --- a/openbb_platform/extensions/derivatives/integration/test_derivatives_api.py +++ b/openbb_platform/extensions/derivatives/integration/test_derivatives_api.py @@ -40,6 +40,7 @@ def headers(): "model": "black_scholes", "show_extended_price": False, "include_related_symbols": False, + "delay": "delayed", } ), ({"provider": "cboe", "symbol": "AAPL", "use_cache": False}), diff --git a/openbb_platform/extensions/derivatives/integration/test_derivatives_python.py b/openbb_platform/extensions/derivatives/integration/test_derivatives_python.py index eb069b761e5..681e2f56f26 100644 --- a/openbb_platform/extensions/derivatives/integration/test_derivatives_python.py +++ b/openbb_platform/extensions/derivatives/integration/test_derivatives_python.py @@ -36,6 +36,7 @@ def obb(pytestconfig): "model": "black_scholes", "show_extended_price": False, "include_related_symbols": False, + "delay": "delayed", } ), ({"provider": "cboe", "symbol": "AAPL", "use_cache": False}), diff --git a/openbb_platform/openbb/assets/reference.json b/openbb_platform/openbb/assets/reference.json index d614e2d7a76..f07699be5f2 100644 --- a/openbb_platform/openbb/assets/reference.json +++ b/openbb_platform/openbb/assets/reference.json @@ -1791,6 +1791,18 @@ ], "intrinio": [ { + "name": "delay", + "type": "Literal['eod', 'realtime', 'delayed']", + "description": "Whether to return delayed, realtime, or eod data.", + "default": "eod", + "optional": true, + "choices": [ + "eod", + "realtime", + "delayed" + ] + }, + { "name": "date", "type": "Union[date, str]", "description": "The end-of-day date for options chains data.", @@ -1875,7 +1887,10 @@ "description": "The pricing model to use for options chains data, default is 'black_scholes'. Parameter is ignored when a date is supplied.", "default": "black_scholes", "optional": true, - "choices": null + "choices": [ + "black_scholes", + "bjerk" + ] }, { "name": "show_extended_price", diff --git a/openbb_platform/openbb/package/derivatives_options.py b/openbb_platform/openbb/package/derivatives_options.py index f976eab64b6..3cd32e30dbe 100644 --- a/openbb_platform/openbb/package/derivatives_options.py +++ b/openbb_platform/openbb/package/derivatives_options.py @@ -41,6 +41,8 @@ class ROUTER_derivatives_options(Container): Symbol to get data for. provider : Optional[Literal['intrinio', 'yfinance']] The provider to use, by default None. If None, the priority list configured in the settings is used. Default priority: intrinio, yfinance. + delay : Literal['eod', 'realtime', 'delayed'] + Whether to return delayed, realtime, or eod data. (provider: intrinio) date : Optional[datetime.date] The end-of-day date for options chains data. (provider: intrinio) option_type : Optional[Literal['call', 'put']] @@ -211,6 +213,32 @@ class ROUTER_derivatives_options(Container): "symbol": symbol, }, extra_params=kwargs, + info={ + "delay": { + "intrinio": { + "multiple_items_allowed": False, + "choices": ["eod", "realtime", "delayed"], + } + }, + "option_type": { + "intrinio": { + "multiple_items_allowed": False, + "choices": ["call", "put"], + } + }, + "moneyness": { + "intrinio": { + "multiple_items_allowed": False, + "choices": ["otm", "itm", "all"], + } + }, + "model": { + "intrinio": { + "multiple_items_allowed": False, + "choices": ["black_scholes", "bjerk"], + } + }, + }, ) ) diff --git a/openbb_platform/providers/intrinio/openbb_intrinio/models/options_chains.py b/openbb_platform/providers/intrinio/openbb_intrinio/models/options_chains.py index 571fe5a0c27..bde534b3e14 100644 --- a/openbb_platform/providers/intrinio/openbb_intrinio/models/options_chains.py +++ b/openbb_platform/providers/intrinio/openbb_intrinio/models/options_chains.py @@ -16,7 +16,7 @@ from openbb_core.provider.standard_models.options_chains import ( from openbb_core.provider.utils.errors import OpenBBError from openbb_intrinio.models.equity_historical import IntrinioEquityHistoricalFetcher from openbb_intrinio.models.index_historical import IntrinioIndexHistoricalFetcher -from pydantic import Field, field_validator +from pydantic import Field, field_validator, model_validator class IntrinioOptionsChainsQueryParams(OptionsChainsQueryParams): @@ -34,20 +34,40 @@ class IntrinioOptionsChainsQueryParams(OptionsChainsQueryParams): "oi_lt": "open_interest_less_than", "option_type": "type", } + __json_schema_extra__ = { + "moneyness": { + "multiple_items_allowed": False, + "choices": ["otm", "itm", "all"], + }, + "delay": { + "multiple_items_allowed": False, + "choices": ["eod", "realtime", "delayed"], + }, + "option_type": { + "multiple_items_allowed": False, + "choices": ["call", "put"], + }, + "model": { + "multiple_items_allowed": False, + "choices": ["black_scholes", "bjerk"], + }, + } + delay: Literal["eod", "realtime", "delayed"] = Field( + description="Whether to return delayed, realtime, or eod data.", + default="eod", + ) date: Optional[dateType] = Field( default=None, description="The end-of-day date for options chains data." ) option_type: Optional[Literal["call", "put"]] = Field( default=None, description="The option type, call or put, 'None' is both (default).", - json_schema_extra={"choices": ["call", "put"]}, ) moneyness: Literal["otm", "itm", "all"] = Field( default="all", description="Return only contracts that are in or out of the money, default is 'all'." + " Parameter is ignored when a date is supplied.", - json_schema_extra={"choices": ["otm", "itm", "all"]}, ) strike_gt: Optional[int] = Field( default=None, @@ -95,6 +115,14 @@ class IntrinioOptionsChainsQueryParams(OptionsChainsQueryParams): + " default is False.", ) + @model_validator(mode="after") + @classmethod + def date_not_allowed_with_realtime(cls, values: Any) -> Any: + """Return an error if the date is supplied when delay is realtime.""" + if values.delay != "eod" and values.date: + warn("Date is ignored when accessing realtime or delayed data.") + return values + class IntrinioOptionsChainsData(OptionsChainsData): """Intrinio Options Chains Data.""" @@ -133,18 +161,25 @@ class IntrinioOptionsChainsData(OptionsChainsData): from dateutil import parser from pytz import timezone - if isinstance(v, str): - dt = parser.parse(v) - dt = dt.replace(tzinfo=timezone("UTC")) - dt = dt.astimezone(timezone("America/New_York")) - return dt.replace(microsecond=0) - return v if v else None + if not v: + return None + new_v: list = [] + for item in v: + if item: + dt = parser.parse(item) + dt = dt.replace(tzinfo=timezone("UTC")) + dt = dt.astimezone(timezone("America/New_York")) + new_v.append(dt.replace(microsecond=0)) + else: + new_v.append(None) + + return new_v @field_validator("volume", "open_interest", mode="before", check_fields=False) @classmethod def _volume_oi_validate(cls, v): """Return the volume as an integer.""" - return 0 if v is None else v + return [0 if item is None else item for item in v] class IntrinioOptionsChainsFetcher( @@ -167,11 +202,14 @@ class IntrinioOptionsChainsFetcher( # pylint: disable=import-outside-toplevel from datetime import timedelta # noqa from openbb_core.provider.utils.helpers import ( - ClientResponse, amake_requests, get_querystring, ) - from openbb_intrinio.utils.helpers import get_data_many, get_weekday + from openbb_intrinio.utils.helpers import ( + get_data_many, + get_weekday, + response_callback, + ) api_key = credentials.get("intrinio_api_key") if credentials else "" @@ -190,8 +228,10 @@ class IntrinioOptionsChainsFetcher( "%Y-%m-%d" ) url = ( - f"{base_url}/expirations/{query.symbol}/eod?" - f"after={date}&api_key={api_key}" + f"{base_url}/expirations/{query.symbol}/" + f"{'eod' if query.delay == 'eod' else 'realtime'}?" + f"{'after=' + date + '&' if query.delay == 'eod' else 'source=' + query.delay + '&'}" + f"api_key={api_key}" ) expirations = await get_data_many(url, "expirations", **kwargs) @@ -231,9 +271,9 @@ class IntrinioOptionsChainsFetcher( return [generate_url(expiration) for expiration in expirations] - async def callback(response: ClientResponse, _: Any) -> List: + async def callback(response, _) -> list: """Return the response.""" - response_data = await response.json() + response_data = await response_callback(response, _) return response_data.get("chain", []) # type: ignore results = await amake_requests( diff --git a/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_options_chains_fetcher_urllib3_v1.yaml b/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_options_chains_fetcher_urllib3_v1.yaml index a5b1ea9c7c4..855ae01fde2 100644 --- a/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_options_chains_fetcher_urllib3_v1.yaml +++ b/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_options_chains_fetcher_urllib3_v1.yaml @@ -13,11 +13,11 @@ interactions: response: body: string: !!binary | - H4sIAPf0iWYAA0zSsU7EMBCE4XdJjaWdtePEvAqioKC4hjsBBRLi3XFiefOXnzJyxpP8Lu8/j9vn - 2/ft/vG1PL8sbl6TPGlfngasEkqqA+sZaxPWiJrcAjm5Av2AbaAcB8xYR3+yBixeWo6jr5jtyTMw - 65ywRnhgS14BNYIxiwbHFXZCgApgcR9bUxbgBRBjMsCu+xQWLSxaWLSwaGbRDgfEmDFmV1Hnos5F - nYs6FxWLikXFooqi+fzajXBAjM2iAwooFj0xFx0wYC6ajx/JN8IAMWZ14vjfGuFAL/r69w8AAP// - AwApJXK4NwMAAA== + H4sIAKkCKWcAA0zSu04FMQyE4XfZmkgeO3sJr4IoKChOAwgokBDvTjZH8f7lJ412x45/l9efj9vn + y/ft/e1reXxa3HwvpqJ1eTixFXnRMWEb0WPbHeuItQlrxJFfW88PuCVq0Z6I4ko4oYzV8z/zAwMK + wLaEijfCgVlnwA5CCSu+AjoIxqxO9LF9Jwy4inZcRft2wgAPQIxZI3Ie24tvgBrBmOU85yschABV + wK551hICvAJiTAbYNU9l0cqilUUriwaLBp6xQ4wZY9cznocUADbq3Khzo2JRsahYVFk0xlk2wgEx + NoveoYRyowNzo3cYMDca40Z3wgAxNu8txlk2woFe9PnvHwAA//8DAOMx7A0UBAAA headers: Connection: - keep-alive @@ -26,7 +26,7 @@ interactions: Content-Type: - application/json Date: - - Sun, 07 Jul 2024 01:52:55 GMT + - Mon, 04 Nov 2024 17:21:45 GMT Transfer-Encoding: - chunked Vary: @@ -44,11 +44,11 @@ interactions: Connection: - keep-alive method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-04-05/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False + uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-08-23/eod?api_key=MOCK_API_KEY&date=2023-09-15&delay=eod&include_related_symbols=False response: body: string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= + H4sIAKoCKWcAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= headers: Connection: - keep-alive @@ -57,7 +57,7 @@ interactions: Content-Type: - application/json Date: - - Sun, 07 Jul 2024 01:52:55 GMT + - Mon, 04 Nov 2024 17:21:46 GMT Transfer-Encoding: - chunked Vary: @@ -75,11 +75,11 @@ interactions: Connection: - keep-alive method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2023-12-22/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False + uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-06-14/eod?api_key=MOCK_API_KEY&date=2023-09-15&delay=eod&include_related_symbols=False response: body: string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= + H4sIAKoCKWcAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= headers: Connection: - keep-alive @@ -88,7 +88,7 @@ interactions: Content-Type: - application/json Date: - - Sun, 07 Jul 2024 01:52:55 GMT + - Mon, 04 Nov 2024 17:21:46 GMT Transfer-Encoding: - chunked Vary: @@ -106,11 +106,11 @@ interactions: Connection: - keep-alive method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-01-05/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False + uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-05-10/eod?api_key=MOCK_API_KEY&date=2023-09-15&delay=eod&include_related_symbols=False response: body: string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= + H4sIAKoCKWcAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= headers: Connection: - keep-alive @@ -119,7 +119,7 @@ interactions: Content-Type: - application/json Date: - - Sun, 07 Jul 2024 01:52:55 GMT + - Mon, 04 Nov 2024 17:21:46 GMT Transfer-Encoding: - chunked Vary: @@ -137,11 +137,11 @@ interactions: Connection: - keep-alive method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2023-12-29/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False + uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-05-24/eod?api_key=MOCK_API_KEY&date=2023-09-15&delay=eod&include_related_symbols=False response: body: string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= + H4sIAKoCKWcAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= headers: Connection: - keep-alive @@ -150,7 +150,7 @@ interactions: Content-Type: - application/json Date: - - Sun, 07 Jul 2024 01:52:55 GMT + - Mon, 04 Nov 2024 17:21:46 GMT Transfer-Encoding: - chunked Vary: @@ -168,11 +168,11 @@ interactions: Connection: - keep-alive method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2023-11-10/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False + uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-03-28/eod?api_key=MOCK_API_KEY&date=2023-09-15&delay=eod&include_related_symbols=False response: body: string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= + H4sIAKoCKWcAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= headers: Connection: - keep-alive @@ -181,7 +181,7 @@ interactions: Content-Type: - application/json Date: - - Sun, 07 Jul 2024 01:52:55 GMT + - Mon, 04 Nov 2024 17:21:46 GMT Transfer-Encoding: - chunked Vary: @@ -199,11 +199,11 @@ interactions: Connection: - keep-alive method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-03-08/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False + uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-07-12/eod?api_key=MOCK_API_KEY&date=2023-09-15&delay=eod&include_related_symbols=False response: body: string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= + H4sIAKoCKWcAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= headers: Connection: - keep-alive @@ -212,7 +212,7 @@ interactions: Content-Type: - application/json Date: - - Sun, 07 Jul 2024 01:52:55 GMT + - Mon, 04 Nov 2024 17:21:46 GMT Transfer-Encoding: - chunked Vary: @@ -230,1166 +230,145 @@ interactions: Connection: - keep-alive method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-08-02/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False + uri: https://api-v2.intrinio.com/options/chain/AAPL/2023-10-06/eod?api_key=MOCK_API_KEY&date=2023-09-15&delay=eod&include_related_symbols=False response: body: string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= - headers: - Connection: - - keep-alive - Content-Encoding: - - gzip - Content-Type: - - application/json - Date: - - Sun, 07 Jul 2024 01:52:55 GMT - Transfer-Encoding: - - chunked - Vary: - - Origin,Accept-Encoding - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-01-26/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False - response: - body: - string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= - headers: - Connection: - - keep-alive - Content-Encoding: - - gzip - Content-Type: - - application/json - Date: - - Sun, 07 Jul 2024 01:52:55 GMT - Transfer-Encoding: - - chunked - Vary: - - Origin,Accept-Encoding - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-07-05/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False - response: - body: - string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= - headers: - Connection: - - keep-alive - Content-Encoding: - - gzip - Content-Type: - - application/json - Date: - - Sun, 07 Jul 2024 01:52:55 GMT - Transfer-Encoding: - - chunked - Vary: - - Origin,Accept-Encoding - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-03-01/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False - response: - body: - string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= - headers: - Connection: - - keep-alive - Content-Encoding: - - gzip - Content-Type: - - application/json - Date: - - Sun, 07 Jul 2024 01:52:55 GMT - Transfer-Encoding: - - chunked - Vary: - - Origin,Accept-Encoding - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-06-28/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False - response: - body: - string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= - headers: - Connection: - - keep-alive - Content-Encoding: - - gzip - Content-Type: - - application/json - Date: - - Sun, 07 Jul 2024 01:52:55 GMT - Transfer-Encoding: - - chunked - Vary: - - Origin,Accept-Encoding - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-03-22/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False - response: - body: - string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= - headers: - Connection: - - keep-alive - Content-Encoding: - - gzip - Content-Type: - - application/json - Date: - - Sun, 07 Jul 2024 01:52:55 GMT - Transfer-Encoding: - - chunked - Vary: - - Origin,Accept-Encoding - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-06-14/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False - response: - body: - string: !!binary | - H4sIAPf0iWYAA6pWSs5IzMxTsoqOrQUAAAD//wMAHQXYeAwAAAA= - headers: - Connection: - - keep-alive - Content-Encoding: - - gzip - Content-Type: - - application/json - Date: - - Sun, 07 Jul 2024 01:52:55 GMT - Transfer-Encoding: - - chunked - Vary: - - Origin,Accept-Encoding - status: - code: 200 - message: OK -- request: - body: null - headers: - Accept: - - application/json - Accept-Encoding: - - gzip, deflate - Connection: - - keep-alive - method: GET - uri: https://api-v2.intrinio.com/options/chain/AAPL/2024-05-03/eod?api_key=MOCK_API_KEY&date=2023-09-15&include_related_symbols=False - response: - body: - string: !!binary | |