diff --git a/openbb_platform/core/openbb_core/provider/standard_models/historical_dividends.py b/openbb_platform/core/openbb_core/provider/standard_models/historical_dividends.py index 63aaf1ca508..c45f2065297 100644 --- a/openbb_platform/core/openbb_core/provider/standard_models/historical_dividends.py +++ b/openbb_platform/core/openbb_core/provider/standard_models/historical_dividends.py @@ -2,7 +2,7 @@ from datetime import date as dateType -from typing import List, Optional, Set, Union +from typing import List, Set, Union from pydantic import Field, field_validator @@ -31,41 +31,4 @@ class HistoricalDividendsData(Data): """Historical Dividends Data.""" date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", "")) - label: str = Field(description="Label of the historical dividends.") - adj_dividend: float = Field( - description="Adjusted dividend of the historical dividends." - ) dividend: float = Field(description="Dividend of the historical dividends.") - record_date: Optional[dateType] = Field( - description="Record date of the historical dividends.", default=None - ) - payment_date: Optional[dateType] = Field( - description="Payment date of the historical dividends.", default=None - ) - declaration_date: Optional[dateType] = Field( - description="Declaration date of the historical dividends.", default=None - ) - - @field_validator("declaration_date", mode="before", check_fields=False) - @classmethod - def declaration_date_validate(cls, v: str): # pylint: disable=E0213 - """Validate declaration date.""" - if not isinstance(v, str): - return v - return dateType.fromisoformat(v) if v else None - - @field_validator("record_date", mode="before", check_fields=False) - @classmethod - def record_date_validate(cls, v: str): # pylint: disable=E0213 - """Record date validator.""" - if not isinstance(v, str): - return v - return dateType.fromisoformat(v) if v else None - - @field_validator("payment_date", mode="before", check_fields=False) - @classmethod - def payment_date_validate(cls, v: str): # pylint: disable=E0213 - """Payment date validator.""" - if not isinstance(v, str): - return v - return dateType.fromisoformat(v) if v else None diff --git a/openbb_platform/extensions/equity/integration/test_equity_api.py b/openbb_platform/extensions/equity/integration/test_equity_api.py index 5eaf730d449..e4596ea09de 100644 --- a/openbb_platform/extensions/equity/integration/test_equity_api.py +++ b/openbb_platform/extensions/equity/integration/test_equity_api.py @@ -96,15 +96,6 @@ def test_equity_fundamental_balance_growth(params, headers): [ ({"start_date": "2023-11-05", "end_date": "2023-11-10", "provider": "fmp"}), ({"start_date": "2023-11-05", "end_date": "2023-11-10", "provider": "nasdaq"}), - ( - { - "start_date": "2023-11-05", - "end_date": "2023-11-10", - "symbol": "AAPL", - "limit": 100, - "provider": "intrinio", - } - ), ], ) @pytest.mark.integration @@ -263,7 +254,16 @@ def test_equity_fundamental_historical_splits(params, headers): @pytest.mark.parametrize( "params", - [({"symbol": "AAPL"})], + [ + ({"symbol": "AAPL", "provider": "fmp"}), + ( + { + "symbol": "AAPL", + "limit": 100, + "provider": "intrinio", + } + ), + ], ) @pytest.mark.integration def test_equity_fundamental_dividends(params, headers): diff --git a/openbb_platform/extensions/equity/integration/test_equity_python.py b/openbb_platform/extensions/equity/integration/test_equity_python.py index f722ac28c6a..13dbdc43fad 100644 --- a/openbb_platform/extensions/equity/integration/test_equity_python.py +++ b/openbb_platform/extensions/equity/integration/test_equity_python.py @@ -96,15 +96,6 @@ def test_equity_fundamental_balance_growth(params, obb): [ ({"start_date": "2023-11-05", "end_date": "2023-11-10", "provider": "fmp"}), ({"start_date": "2023-11-05", "end_date": "2023-11-10", "provider": "nasdaq"}), - ( - { - "start_date": "2023-11-05", - "end_date": "2023-11-10", - "symbol": "AAPL", - "limit": 100, - "provider": "intrinio", - } - ), ], ) @pytest.mark.integration @@ -250,6 +241,14 @@ def test_equity_fundamental_historical_splits(params, obb): "params", [ ({"symbol": "AAPL"}), + ({"symbol": "AAPL", "provider": "fmp"}), + ( + { + "symbol": "AAPL", + "limit": 100, + "provider": "intrinio", + } + ), ], ) @pytest.mark.integration diff --git a/openbb_platform/providers/fmp/openbb_fmp/models/historical_dividends.py b/openbb_platform/providers/fmp/openbb_fmp/models/historical_dividends.py index fe8883634ae..f178196f327 100644 --- a/openbb_platform/providers/fmp/openbb_fmp/models/historical_dividends.py +++ b/openbb_platform/providers/fmp/openbb_fmp/models/historical_dividends.py @@ -1,5 +1,6 @@ """FMP Historical Dividends Model.""" +from datetime import date as dateType from typing import Any, Dict, List, Optional from openbb_core.provider.abstract.fetcher import Fetcher @@ -8,6 +9,7 @@ from openbb_core.provider.standard_models.historical_dividends import ( HistoricalDividendsQueryParams, ) from openbb_fmp.utils.helpers import create_url, get_data_many +from pydantic import Field, field_validator class FMPHistoricalDividendsQueryParams(HistoricalDividendsQueryParams): @@ -20,6 +22,37 @@ class FMPHistoricalDividendsQueryParams(HistoricalDividendsQueryParams): class FMPHistoricalDividendsData(HistoricalDividendsData): """FMP Historical Dividends Data.""" + label: str = Field(description="Label of the historical dividends.") + adj_dividend: float = Field( + description="Adjusted dividend of the historical dividends." + ) + record_date: Optional[dateType] = Field( + default=None, + description="Record date of the historical dividends.", + ) + payment_date: Optional[dateType] = Field( + default=None, + description="Payment date of the historical dividends.", + ) + declaration_date: Optional[dateType] = Field( + default=None, + description="Declaration date of the historical dividends.", + ) + + @field_validator( + "declaration_date", + "record_date", + "payment_date", + mode="before", + check_fields=False, + ) + @classmethod + def date_validate(cls, v: str): # pylint: disable=E0213 + """Validate dates.""" + if not isinstance(v, str): + return v + return dateType.fromisoformat(v) if v else None + class FMPHistoricalDividendsFetcher( Fetcher[ diff --git a/openbb_platform/providers/intrinio/openbb_intrinio/__init__.py b/openbb_platform/providers/intrinio/openbb_intrinio/__init__.py index a7b80021f37..c4e70f9eb82 100644 --- a/openbb_platform/providers/intrinio/openbb_intrinio/__init__.py +++ b/openbb_platform/providers/intrinio/openbb_intrinio/__init__.py @@ -2,7 +2,6 @@ from openbb_core.provider.abstract.provider import Provider from openbb_intrinio.models.balance_sheet import IntrinioBalanceSheetFetcher -from openbb_intrinio.models.calendar_dividend import IntrinioCalendarDividendFetcher from openbb_intrinio.models.calendar_ipo import IntrinioCalendarIpoFetcher from openbb_intrinio.models.cash_flow import IntrinioCashFlowStatementFetcher from openbb_intrinio.models.company_filings import IntrinioCompanyFilingsFetcher @@ -15,6 +14,9 @@ from openbb_intrinio.models.fred_series import IntrinioFredSeriesFetcher from openbb_intrinio.models.historical_attributes import ( IntrinioHistoricalAttributesFetcher, ) +from openbb_intrinio.models.historical_dividends import ( + IntrinioHistoricalDividendsFetcher, +) from openbb_intrinio.models.income_statement import IntrinioIncomeStatementFetcher from openbb_intrinio.models.insider_trading import IntrinioInsiderTradingFetcher from openbb_intrinio.models.institutional_ownership import ( @@ -44,12 +46,12 @@ intrinio_provider = Provider( "CompanyFilings": IntrinioCompanyFilingsFetcher, "CompanyNews": IntrinioCompanyNewsFetcher, "CurrencyPairs": IntrinioCurrencyPairsFetcher, - "CalendarDividend": IntrinioCalendarDividendFetcher, "EquityHistorical": IntrinioEquityHistoricalFetcher, "EquityInfo": IntrinioEquityInfoFetcher, "EquityQuote": IntrinioEquityQuoteFetcher, "FredSeries": IntrinioFredSeriesFetcher, "HistoricalAttributes": IntrinioHistoricalAttributesFetcher, + "HistoricalDividends": IntrinioHistoricalDividendsFetcher, "IncomeStatement": IntrinioIncomeStatementFetcher, "InsiderTrading": IntrinioInsiderTradingFetcher, "InstitutionalOwnership": IntrinioInstitutionalOwnershipFetcher, diff --git a/openbb_platform/providers/intrinio/openbb_intrinio/models/calendar_dividend.py b/openbb_platform/providers/intrinio/openbb_intrinio/models/historical_dividends.py similarity index 68% rename from openbb_platform/providers/intrinio/openbb_intrinio/models/calendar_dividend.py rename to openbb_platform/providers/intrinio/openbb_intrinio/models/historical_dividends.py index 58e41b5a12f..6bf07fb8c42 100644 --- a/openbb_platform/providers/intrinio/openbb_intrinio/models/calendar_dividend.py +++ b/openbb_platform/providers/intrinio/openbb_intrinio/models/historical_dividends.py @@ -1,13 +1,13 @@ -"""Intrinio Dividend Calendar Model.""" +"""Intrinio Historical Dividends Model.""" from datetime import datetime from typing import Any, Dict, List, Optional from dateutil.relativedelta import relativedelta from openbb_core.provider.abstract.fetcher import Fetcher -from openbb_core.provider.standard_models.calendar_dividend import ( - CalendarDividendData, - CalendarDividendQueryParams, +from openbb_core.provider.standard_models.historical_dividends import ( + HistoricalDividendsData, + HistoricalDividendsQueryParams, ) from openbb_core.provider.utils.descriptions import QUERY_DESCRIPTIONS from openbb_core.provider.utils.helpers import get_querystring @@ -15,13 +15,12 @@ from openbb_intrinio.utils.helpers import get_data_many from pydantic import Field -class IntrinioCalendarDividendQueryParams(CalendarDividendQueryParams): - """Intrinio Dividend Calendar Query. +class IntrinioHistoricalDividendsQueryParams(HistoricalDividendsQueryParams): + """Intrinio Historical Dividends Query. Source: https://docs.intrinio.com/documentation/web_api/get_security_stock_price_adjustments_v2 """ - symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", "")) limit: Optional[int] = Field( default=100, description=QUERY_DESCRIPTIONS.get("limit", ""), @@ -29,12 +28,8 @@ class IntrinioCalendarDividendQueryParams(CalendarDividendQueryParams): ) -class IntrinioCalendarDividendData(CalendarDividendData): - """Intrinio Dividend Calendar Data.""" - - __alias_dict__ = { - "amount": "dividend", - } +class IntrinioHistoricalDividendsData(HistoricalDividendsData): + """Intrinio Historical Dividends Data.""" factor: float = Field( description=( @@ -50,16 +45,18 @@ class IntrinioCalendarDividendData(CalendarDividendData): ) -class IntrinioCalendarDividendFetcher( +class IntrinioHistoricalDividendsFetcher( Fetcher[ - IntrinioCalendarDividendQueryParams, - List[IntrinioCalendarDividendData], + IntrinioHistoricalDividendsQueryParams, + List[IntrinioHistoricalDividendsData], ] ): """Transform the query, extract and transform the data from the Intrinio endpoints.""" @staticmethod - def transform_query(params: Dict[str, Any]) -> IntrinioCalendarDividendQueryParams: + def transform_query( + params: Dict[str, Any] + ) -> IntrinioHistoricalDividendsQueryParams: """Transform the query params.""" transformed_params = params @@ -69,11 +66,11 @@ class IntrinioCalendarDividendFetcher( if params.get("end_date") is None: transformed_params["end_date"] = now - return IntrinioCalendarDividendQueryParams(**transformed_params) + return IntrinioHistoricalDividendsQueryParams(**transformed_params) @staticmethod def extract_data( - query: IntrinioCalendarDividendQueryParams, + query: IntrinioHistoricalDividendsQueryParams, credentials: Optional[Dict[str, str]], **kwargs: Any, ) -> List[Dict]: @@ -88,12 +85,12 @@ class IntrinioCalendarDividendFetcher( @staticmethod def transform_data( - query: IntrinioCalendarDividendQueryParams, data: List[Dict], **kwargs: Any - ) -> List[IntrinioCalendarDividendData]: + query: IntrinioHistoricalDividendsQueryParams, data: List[Dict], **kwargs: Any + ) -> List[IntrinioHistoricalDividendsData]: """Return the transformed data.""" transformed_data: List[Dict] = [ {"symbol": query.symbol, **item} for item in data ] return [ - IntrinioCalendarDividendData.model_validate(d) for d in transformed_data + IntrinioHistoricalDividendsData.model_validate(d) for d in transformed_data ] diff --git a/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_calendar_dividend_fetcher.yaml b/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_historical_dividends_fetcher.yaml similarity index 91% rename from openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_calendar_dividend_fetcher.yaml rename to openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_historical_dividends_fetcher.yaml index 0a1e37b3e3d..e22d63425be 100644 --- a/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_calendar_dividend_fetcher.yaml +++ b/openbb_platform/providers/intrinio/tests/record/http/test_intrinio_fetchers/test_intrinio_historical_dividends_fetcher.yaml @@ -13,7 +13,7 @@ interactions: response: body: string: !!binary | - H4sIAONzX2UAA5RRW2vCMBT+KyPPKklr7OVN2ZDB5i7icIwRQhpjtE1Lkg6r+N934gbDvu3xfNdz + H4sIABJIZmUAA5RRW2vCMBT+KyPPKklr7OVN2ZDB5i7icIwRQhpjtE1Lkg6r+N934gbDvu3xfNdz khNyvhZ71lgtJOPFrnW+ksY7lH+cUMG9RDmKcBQPMR2SCA3QhgtfW5TjUZalE5ImmOKYZgkZoEJ/ 6UKaIpDR+G9morVWGtFB1mp5CyGuKbVnlntdo5yM8HnQK4uGBPfLxgmlOE3IhJC4Vxb/q+wTMAky 7UF0QhoyAsC42lm1A4eoq4abjl0YGNhiPZkfn0LW5bXkQWy5UfJH4A6K1cdHm3UgMLwKV0ybppQ3 @@ -27,7 +27,7 @@ interactions: Content-Type: - application/json Date: - - Thu, 23 Nov 2023 15:46:43 GMT + - Tue, 28 Nov 2023 20:05:38 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 67e9a3bcdaf..9dc9f67c82b 100644 --- a/openbb_platform/providers/intrinio/tests/test_intrinio_fetchers.py +++ b/openbb_platform/providers/intrinio/tests/test_intrinio_fetchers.py @@ -4,7 +4,6 @@ from unittest import mock import pytest from openbb_core.app.service.user_service import UserService from openbb_intrinio.models.balance_sheet import IntrinioBalanceSheetFetcher -from openbb_intrinio.models.calendar_dividend import IntrinioCalendarDividendFetcher from openbb_intrinio.models.calendar_ipo import IntrinioCalendarIpoFetcher from openbb_intrinio.models.cash_flow import IntrinioCashFlowStatementFetcher from openbb_intrinio.models.company_filings import IntrinioCompanyFilingsFetcher @@ -17,6 +16,9 @@ from openbb_intrinio.models.fred_series import IntrinioFredSeriesFetcher from openbb_intrinio.models.historical_attributes import ( IntrinioHistoricalAttributesFetcher, ) +from openbb_intrinio.models.historical_dividends import ( + IntrinioHistoricalDividendsFetcher, +) from openbb_intrinio.models.income_statement import IntrinioIncomeStatementFetcher from openbb_intrinio.models.insider_trading import IntrinioInsiderTradingFetcher from openbb_intrinio.models.institutional_ownership import ( @@ -238,14 +240,14 @@ def test_intrinio_market_indices_fetcher(credentials=test_credentials): @pytest.mark.record_http -def test_intrinio_calendar_dividend_fetcher(credentials=test_credentials): +def test_intrinio_historical_dividends_fetcher(credentials=test_credentials): params = { "symbol": "AAPL", "start_date": date(2023, 1, 1), "end_date": date(2023, 6, 6), } - fetcher = IntrinioCalendarDividendFetcher() + fetcher = IntrinioHistoricalDividendsFetcher() result = fetcher.test(params, credentials) assert result is None