refactored EarningsCalendar for stocks.fa.cal

This commit is contained in:
Pratyush Shukla
2023-07-26 22:23:14 +05:30
parent 3cfb8f29cb
commit dca3001ea6
2 changed files with 53 additions and 60 deletions

View File

@@ -1,10 +1,10 @@
"""FMP Earnings Calendar fetcher."""
from datetime import date as dateType
from datetime import datetime
from typing import Dict, List, Optional
from openbb_provider.abstract.data import Data
from openbb_provider.abstract.fetcher import Fetcher
from openbb_provider.helpers import data_transformer
from openbb_provider.models.earnings_calendar import (
@@ -14,30 +14,38 @@ from openbb_provider.models.earnings_calendar import (
from openbb_fmp.utils.helpers import create_url, get_data_many
from pydantic import validator
class FMPEarningsCalendarQueryParams(EarningsCalendarQueryParams):
"""FMP Earnings Calendar query.
"""FMP Earnings Calendar Query.
Source: https://site.financialmodelingprep.com/developer/docs/earnings-calendar-api/
Parameter
---------
symbol : str
The symbol of the company.
limit : int
"""
class FMPEarningsCalendarData(Data):
date: dateType
symbol: str
eps: Optional[float]
epsEstimated: Optional[float]
time: str
revenue: Optional[int]
revenueEstimated: Optional[int]
updatedFromDate: Optional[dateType]
fiscalDateEnding: dateType
class FMPEarningsCalendarData(EarningsCalendarData):
"""FMP Earnings Calendar Data."""
class Config:
fields = {
"eps_estimated": "epsEstimated",
"revenue_estimated": "revenueEstimated",
"updated_from_date": "updatedFromDate",
"fiscal_date_ending": "fiscalDateEnding",
}
@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("updatedFromDate", pre=True, check_fields=False)
def updated_from_date_validate(cls, v: str): # pylint: disable=E0213
return datetime.strptime(v, "%Y-%m-%d") if v else None
@validator("fiscalDateEnding", pre=True, check_fields=False)
def fiscal_date_ending_validate(cls, v: str): # pylint: disable=E0213
return datetime.strptime(v, "%Y-%m-%d") if v else None
class FMPEarningsCalendarFetcher(

View File

@@ -6,52 +6,37 @@ from typing import Optional
from openbb_provider.abstract.data import Data, QueryParams
from openbb_provider.models.base import BaseSymbol
from openbb_provider.metadata import QUERY_DESCRIPTIONS, DATA_DESCRIPTIONS
from pydantic import Field, NonNegativeFloat
class EarningsCalendarQueryParams(QueryParams, BaseSymbol):
"""Earnings calendar rating query model.
"""Earnings calendar rating Query."""
Parameter
---------
symbol : str
The symbol of the company.
limit : int
"""
limit: Optional[int]
limit: Optional[int] = Field(
default=50, description=QUERY_DESCRIPTIONS.get("limit", "")
)
class EarningsCalendarData(Data, BaseSymbol):
"""Earnings calendar data.
"""Earnings calendar Data."""
Returns
-------
symbol : str
The symbol of the asset.
date : date
The date of the earnings calendar.
eps : float
The EPS of the earnings calendar.
eps_estimated : float
The estimated EPS of the earnings calendar.
time : str
The time of the earnings calendar.
revenue : int
The revenue of the earnings calendar.
revenue_estimated : int
The estimated revenue of the earnings calendar.
updated_from_date : date
The updated from date of the earnings calendar.
fiscal_date_ending : date
The fiscal date ending of the earnings calendar.
"""
date: dateType
symbol: str
eps: Optional[float]
eps_estimated: Optional[float]
time: str
revenue: Optional[int]
revenue_estimated: Optional[int]
updated_from_date: Optional[dateType]
fiscal_date_ending: dateType
date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
eps: Optional[NonNegativeFloat] = Field(
description="The EPS of the earnings calendar."
)
eps_estimated: Optional[NonNegativeFloat] = Field(
description="The estimated EPS of the earnings calendar."
)
time: str = Field(description="The time of the earnings calendar.")
revenue: Optional[int] = Field(description="The revenue of the earnings calendar.")
revenue_estimated: Optional[int] = Field(
description="The estimated revenue of the earnings calendar."
)
updated_from_date: Optional[dateType] = Field(
description="The updated from date of the earnings calendar."
)
fiscal_date_ending: dateType = Field(
description="The fiscal date ending of the earnings calendar."
)