diff --git a/openbb_sdk/providers/fmp/openbb_fmp/models/dividend_calendar.py b/openbb_sdk/providers/fmp/openbb_fmp/models/dividend_calendar.py index 878937f0f03..831c811ea57 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/dividend_calendar.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/dividend_calendar.py @@ -1,6 +1,6 @@ """FMP Dividend Calendar fetcher.""" -from datetime import datetime +from datetime import datetime, timedelta from typing import Dict, List, Optional from openbb_provider.abstract.fetcher import Fetcher @@ -15,40 +15,39 @@ from openbb_fmp.utils.helpers import get_data_many, get_querystring class FMPDividendCalendarQueryParams(DividendCalendarQueryParams): - """FMP Dividend Calendar query. + """FMP Dividend Calendar Query. Source: https://site.financialmodelingprep.com/developer/docs/dividend-calendar-api/ The maximum time interval between the start and end date can be 3 months. Default value for time interval is 1 month. - - Parameter - --------- - start_date : date - The starting date to fetch the dividend calendar from. Default value is the - previous day from the last month. - end_date : date - The ending date to fetch the dividend calendar till. Default value is the - previous day from the current month. """ class FMPDividendCalendarData(DividendCalendarData): - """FMP Dividend Calendar data.""" + """FMP Dividend Calendar Data.""" - @validator("date", pre=True) + class Config: + fields = { + "adj_dividend": "adjDividend", + "record_date": "recordDate", + "payment_date": "paymentDate", + "declaration_date": "declarationDate", + } + + @validator("date", pre=True, check_fields=False) def date_validate(cls, v: str): # pylint: disable=E0213 return datetime.strptime(v, "%Y-%m-%d") if v else None - @validator("recordDate", pre=True) + @validator("recordDate", pre=True, check_fields=False) def record_date_validate(cls, v: str): # pylint: disable=E0213 return datetime.strptime(v, "%Y-%m-%d") if v else None - @validator("paymentDate", pre=True) + @validator("paymentDate", pre=True, check_fields=False) def payment_date_validate(cls, v: str): # pylint: disable=E0213 return datetime.strptime(v, "%Y-%m-%d") if v else None - @validator("declarationDate", pre=True) + @validator("declarationDate", pre=True, check_fields=False) def declaration_date_validate(cls, v: str): # pylint: disable=E0213 return datetime.strptime(v, "%Y-%m-%d") if v else None @@ -65,9 +64,10 @@ class FMPDividendCalendarFetcher( def transform_query( query: DividendCalendarQueryParams, extra_params: Optional[Dict] = None ) -> FMPDividendCalendarQueryParams: + now = datetime.now().date() return FMPDividendCalendarQueryParams( - start_date=query.start_date, - end_date=query.end_date, + start_date=query.start_date or (now - timedelta(days=31)), + end_date=query.end_date or (now - timedelta(days=1)), **extra_params or {}, ) diff --git a/openbb_sdk/sdk/provider/openbb_provider/models/dividend_calendar.py b/openbb_sdk/sdk/provider/openbb_provider/models/dividend_calendar.py index 7225371e06e..2f5eb3d4b47 100644 --- a/openbb_sdk/sdk/provider/openbb_provider/models/dividend_calendar.py +++ b/openbb_sdk/sdk/provider/openbb_provider/models/dividend_calendar.py @@ -1,73 +1,44 @@ """Dividend Calendar data model.""" -from datetime import ( - date as dateType, - datetime, - timedelta, -) +from datetime import date as dateType, datetime, timedelta from typing import Optional from pydantic import Field, NonNegativeFloat from openbb_provider.abstract.data import Data, QueryParams -from openbb_provider.metadata import QUERY_DESCRIPTIONS +from openbb_provider.metadata import QUERY_DESCRIPTIONS, DATA_DESCRIPTIONS +from openbb_provider.models.base import BaseSymbol class DividendCalendarQueryParams(QueryParams): - """Dividend Calendar query. - - The maximum time interval between the start and end date can be 3 months. - Default value for time interval is 1 month. - - Parameter - --------- - start_date : date - The starting date to fetch the dividend calendar from. Default value is the - previous day from the last month. - end_date : date - The ending date to fetch the dividend calendar till. Default value is the - previous day from the current month. - """ + """Dividend Calendar Query.""" start_date: Optional[dateType] = Field( - description=QUERY_DESCRIPTIONS.get("start_date", ""), - default=datetime.now().date() - timedelta(days=31), + description=QUERY_DESCRIPTIONS.get("start_date", "") ) end_date: Optional[dateType] = Field( - description=QUERY_DESCRIPTIONS.get("end_date", ""), - default=datetime.now().date() - timedelta(days=1), + description=QUERY_DESCRIPTIONS.get("end_date", "") ) -class DividendCalendarData(Data): - """Dividend Calendar data. +class DividendCalendarData(Data, BaseSymbol): + """Dividend Calendar Data.""" - Returns - ------- - date : dateType - The date of the dividend in the calendar. - label : str - The date in human readable form in the calendar. - adjDividend : Optional[NonNegativeFloat] - The adjusted dividend on a date in the calendar. - symbol : str - The symbol of the company for which the dividend is returned in the calendar. - dividend : Optional[NonNegativeFloat] - The dividend amount in the calendar. - recordDate : Optional[dateType] - The record date of the dividend in the calendar. - paymentDate : Optional[dateType] - The payment date of the dividend in the calendar. - declarationDate : Optional[dateType] - The declaration date of the dividend in the calendar. - """ - - date: dateType - label: str - adjDividend: Optional[NonNegativeFloat] = Field(alias="adj_dividend") - symbol: str - dividend: Optional[NonNegativeFloat] - recordDate: Optional[dateType] = Field(alias="record_date") - paymentDate: Optional[dateType] = Field(alias="payment_date") - declarationDate: Optional[dateType] = Field(alias="declaration_date") + date: dateType = Field(description=DATA_DESCRIPTIONS.get("date")) + label: str = Field(description="The date in human readable form in the calendar.") + adj_dividend: Optional[NonNegativeFloat] = Field( + description="The adjusted dividend on a date in the calendar.", + ) + dividend: Optional[NonNegativeFloat] = Field( + description="The dividend amount in the calendar." + ) + record_date: Optional[dateType] = Field( + description="The record date of the dividend in the calendar.", + ) + payment_date: Optional[dateType] = Field( + description="The payment date of the dividend in the calendar.", + ) + declaration_date: Optional[dateType] = Field( + description="The declaration date of the dividend in the calendar.", + )