diff options
author | Danglewood <85772166+deeleeramone@users.noreply.github.com> | 2024-01-25 12:41:53 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-25 20:41:53 +0000 |
commit | 305b8656378dff73f4d3268f96c95797b447b80f (patch) | |
tree | 01e714040fcda6b09900eb33ce5649428a35192a | |
parent | dff51f25d3433274f9abe3011c2bdff773600886 (diff) |
hotfix/intrinio-index: Drop None Rows From intrinio Historical Index (#5987)
* drop None rows from intrinio historical indexes
* add empty data error
* static assets
8 files changed, 66 insertions, 52 deletions
diff --git a/openbb_platform/core/openbb_core/provider/standard_models/index_historical.py b/openbb_platform/core/openbb_core/provider/standard_models/index_historical.py index 2e19d327260..1443562936b 100644 --- a/openbb_platform/core/openbb_core/provider/standard_models/index_historical.py +++ b/openbb_platform/core/openbb_core/provider/standard_models/index_historical.py @@ -40,7 +40,9 @@ class IndexHistoricalQueryParams(QueryParams): class IndexHistoricalData(Data): """Index Historical Data.""" - date: datetime = Field(description=DATA_DESCRIPTIONS.get("date", "")) + date: Union[dateType, datetime] = Field( + description=DATA_DESCRIPTIONS.get("date", "") + ) open: Optional[StrictFloat] = Field( default=None, description=DATA_DESCRIPTIONS.get("open", "") ) @@ -58,6 +60,10 @@ class IndexHistoricalData(Data): ) @field_validator("date", mode="before", check_fields=False) - def date_validate(cls, v): # pylint: disable=E0213 + @classmethod + def date_validate(cls, v): """Return formatted datetime.""" - return parser.isoparse(str(v)) + v = parser.isoparse(str(v)) + if v.hour == 0 and v.minute == 0: + return v.date() + return v diff --git a/openbb_platform/extensions/index/integration/test_index_api.py b/openbb_platform/extensions/index/integration/test_index_api.py index d8094ad8f9a..3b7fa9c7be4 100644 --- a/openbb_platform/extensions/index/integration/test_index_api.py +++ b/openbb_platform/extensions/index/integration/test_index_api.py @@ -134,11 +134,9 @@ def test_index_constituents(params, headers): "provider": "intrinio", "start_date": "2023-01-01", "end_date": "2023-06-06", - "symbol": "$DJI", - "tag": "level", + "symbol": "DJI", "sort": "desc", "limit": 100, - "type": None, } ), ], diff --git a/openbb_platform/extensions/index/integration/test_index_python.py b/openbb_platform/extensions/index/integration/test_index_python.py index b8073621a7c..7e5787518c7 100644 --- a/openbb_platform/extensions/index/integration/test_index_python.py +++ b/openbb_platform/extensions/index/integration/test_index_python.py @@ -121,11 +121,9 @@ def test_index_constituents(params, obb): "provider": "intrinio", "start_date": "2023-01-01", "end_date": "2023-06-06", - "symbol": "$DJI", - "tag": "level", + "symbol": "DJI", "sort": "desc", "limit": 100, - "type": None, } ), ], diff --git a/openbb_platform/openbb/package/extension_map.json b/openbb_platform/openbb/package/extension_map.json index d2deb1107cc..cb31119c7f8 100644 --- a/openbb_platform/openbb/package/extension_map.json +++ b/openbb_platform/openbb/package/extension_map.json @@ -24,4 +24,4 @@ "tradingeconomics@1.1.1", "yfinance@1.1.1" ] -}
\ No newline at end of file +} diff --git a/openbb_platform/openbb/package/module_map.json b/openbb_platform/openbb/package/module_map.json index a14f4bc4032..3c43bc00321 100644 --- a/openbb_platform/openbb/package/module_map.json +++ b/openbb_platform/openbb/package/module_map.json @@ -140,4 +140,4 @@ "regulators_sec_schema_files": "/regulators/sec/schema_files", "regulators_sec_sic_search": "/regulators/sec/sic_search", "regulators_sec_symbol_map": "/regulators/sec/symbol_map" -}
\ No newline at end of file +} diff --git a/openbb_platform/providers/intrinio/openbb_intrinio/models/index_historical.py b/openbb_platform/providers/intrinio/openbb_intrinio/models/index_historical.py index 9acd91c68a1..40977203414 100644 --- a/openbb_platform/providers/intrinio/openbb_intrinio/models/index_historical.py +++ b/openbb_platform/providers/intrinio/openbb_intrinio/models/index_historical.py @@ -10,29 +10,25 @@ from openbb_core.provider.standard_models.index_historical import ( IndexHistoricalQueryParams, ) from openbb_core.provider.utils.descriptions import QUERY_DESCRIPTIONS -from openbb_core.provider.utils.helpers import get_querystring -from openbb_intrinio.utils.helpers import get_data_many +from openbb_core.provider.utils.errors import EmptyDataError +from openbb_core.provider.utils.helpers import amake_requests, get_querystring from pydantic import Field, NonNegativeInt class IntrinioIndexHistoricalQueryParams(IndexHistoricalQueryParams): """Intrinio Index Historical Query. - Source: https://docs.intrinio.com/documentation/web_api/get_stock_market_index_historical_data_v2 + Source: + https://docs.intrinio.com/documentation/web_api/get_stock_market_index_historical_data_v2 """ - tag: Optional[str] = Field(default="level", description="Index tag.") - type: Optional[str] = Field( - default=None, - description="Index type.", - ) sort: Literal["asc", "desc"] = Field( - default="desc", + default="asc", description="Sort order.", alias="sort_order", ) limit: NonNegativeInt = Field( - default=1000, + default=10000, description=QUERY_DESCRIPTIONS.get("limit", ""), alias="page_size", ) @@ -73,13 +69,30 @@ class IntrinioIndexHistoricalFetcher( **kwargs: Any, ) -> List[Dict]: """Return the raw data from the Intrinio endpoint.""" + results = [] api_key = credentials.get("intrinio_api_key") if credentials else "" - + symbols = query.symbol.replace("$", "").replace("^", "").split(",") base_url = "https://api-v2.intrinio.com/indices/stock_market" - query_str = get_querystring(query.model_dump(by_alias=True), ["symbol", "tag"]) - url = f"{base_url}/{query.symbol}/historical_data/{query.tag}?{query_str}&api_key={api_key}" - - return await get_data_many(url, "historical_data", **kwargs) + query_str = get_querystring(query.model_dump(by_alias=True), ["symbol"]) + urls = [ + f"{base_url}/${symbol}/historical_data/level?{query_str}&api_key={api_key}" + for symbol in symbols + ] + + async def callback(response, _) -> List[Dict]: + """Response callback.""" + _response = await response.json() + data = _response.get("historical_data") + symbol = _response["index"].get("symbol").replace("$", "") + data = [d for d in data if d.get("value") is not None] + data = [{"symbol": symbol, **d} for d in data] if len(symbols) > 1 else data + return results.extend(data) if len(data) > 0 else results # type: ignore + + await amake_requests(urls, callback, **kwargs) + + if len(results) == 0: + raise EmptyDataError() + return results @staticmethod def transform_data( diff --git a/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_index_historical_fetcher.yaml b/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_index_historical_fetcher.yaml index 4327fe36106..33b72674f1d 100644 --- a/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_index_historical_fetcher.yaml +++ b/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_index_historical_fetcher.yaml @@ -3,36 +3,36 @@ interactions: body: null headers: Accept: - - '*/*' + - application/json Accept-Encoding: - - gzip, deflate, br + - gzip, deflate Connection: - keep-alive method: GET - uri: https://api-v2.intrinio.com/indices/stock_market/$DJI/historical_data/level?api_key=MOCK_API_KEY&end_date=2023-06-06&page_size=1000&sort_order=desc&start_date=2023-01-01 + uri: https://api-v2.intrinio.com/indices/stock_market/$DJI/historical_data/level?api_key=MOCK_API_KEY&end_date=2023-06-06&page_size=10000&sort_order=asc&start_date=2023-01-01 response: body: string: !!binary | - H4sIAGQlZWUAA3RYTW8bRwz9K4LQoz0YkvPpm4FckkMubS8tCmFjbRoB8iqVVm4cI/+93KRFlzPP - gA6W9oEzfOQj3/pl++lwmU/nw8Nw3O2Hedje/f6y1T/G7d2WPcutT/rZ3myfhuNVfxSJWRyXbzc9 - LBpYYlcSgvEalhWWIYzWMJ/IxdzB4q2sYVx9cQxh3kQLemifQrzl+j9suh6PCGLI8FWcBARbk8E5 - BZciggUDq9VVRjAxh8boIiGYoZZLchFlSXUNC5xcEgQrpp4SXUWHUrbRvMuoAmR5I3aEeCPTRBKK - 65tDUSZR8d4lRBuRhVVMG3mbKDlBfPhq+5tcQdG8oS2RZlARzCSacnCCauXXDSLE2WVEmzcNEig4 - hjDDWyrBRZjpmrfgI7m+ouGWi0HV4qivlcJMfxTtNgxLtlbKLjzUDhnxrvQZBKsrKTm6ng5Fmf4o - OjwqvJrpj6yyAt0WGlmVmp3v+yM0sqoZqi80sqolO+r7Q2E2Ub1bQLSRmFpxRU0ZGl2loAMEoajt - ogyDWVkt0wjR5leJwpkbmgUUSnSMDrSSCkWHPDzQUKZkIOWFRlJJG5J6MsQuIB3h4RXYmgwusTrf - V13MAtJglMH4E6s8lqpqR2ca5XEQdr5PVJodxJLRUBC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nGaVfjid58+bu4dx+TfLj9+u03x+0l9+nQ7zuN/8POspL5vTp5Xo+mU5+vbTefzrOk73i3q/ + Oxyf9Kfj7jJvX37fv8TGL8/sX3y4DeF2eYx5/5sqTx8v4/lxNx9O0/Yy787zD3ngf1/la8E4mdVo + +K7Bjl/n7ZclpBdT/AMAAP//AwCMqInFMBIAAA== headers: Connection: - keep-alive @@ -41,7 +41,7 @@ interactions: Content-Type: - application/json Date: - - Mon, 27 Nov 2023 23:25:24 GMT + - Tue, 23 Jan 2024 20:30:10 GMT Transfer-Encoding: - chunked Vary: diff --git a/openbb_platform/providers/intrinio/tests/test_intrinio_fetchers.py b/openbb_platform/providers/intrinio/tests/test_intrinio_fetchers.py index 4fead500911..866e2537150 100644 --- a/openbb_platform/providers/intrinio/tests/test_intrinio_fetchers.py +++ b/openbb_platform/providers/intrinio/tests/test_intrinio_fetchers.py @@ -246,8 +246,7 @@ def test_intrinio_market_indices_fetcher(credentials=test_credentials): @pytest.mark.record_http def test_intrinio_index_historical_fetcher(credentials=test_credentials): params = { - "symbol": "$DJI", - "tag": "level", + "symbol": "DJI", "start_date": date(2023, 1, 1), "end_date": date(2023, 6, 6), } |