From 9fe93c0456b1bcade33b895faee9dcef560c9012 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Wed, 2 Aug 2023 00:51:15 +0530 Subject: [PATCH] refactored `PriceTarget` for `stocks.fa.pta` --- .../fmp/openbb_fmp/models/price_target.py | 44 ++++++------ .../openbb_provider/models/price_target.py | 69 +++++++------------ 2 files changed, 47 insertions(+), 66 deletions(-) diff --git a/openbb_sdk/providers/fmp/openbb_fmp/models/price_target.py b/openbb_sdk/providers/fmp/openbb_fmp/models/price_target.py index 712a90d6b59..3e8870e2212 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/price_target.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/price_target.py @@ -4,38 +4,41 @@ from datetime import datetime from typing import Any, Dict, List, Optional -from openbb_provider.abstract.data import Data from openbb_provider.abstract.fetcher import Fetcher from openbb_provider.models.price_target import PriceTargetData, PriceTargetQueryParams -from pydantic import Field from openbb_fmp.utils.helpers import create_url, get_data_many +from pydantic import validator + class FMPPriceTargetQueryParams(PriceTargetQueryParams): - """FMP Price Target query. + """FMP Price Target Query. Source: https://site.financialmodelingprep.com/developer/docs/#Price-Target - - Parameter - --------- - symbol : str - The symbol of the company. """ -class FMPPriceTargetData(Data): - symbol: str - publishedDate: datetime - newsURL: str = Field(alias="news_url") - newsTitle: Optional[str] - analystName: Optional[str] - priceTarget: float - adjPriceTarget: float - priceWhenPosted: float - newsPublisher: str - newsBaseURL: str = Field(alias="news_base_url") - analystCompany: str +class FMPPriceTargetData(PriceTargetData): + """FMP Price Target Data.""" + + class Config: + fields = { + "published_date": "publishedDate", + "news_url": "newsURL", + "news_title": "newsTitle", + "analyst_name": "analystName", + "price_target": "priceTarget", + "adj_price_target": "adjPriceTarget", + "price_when_posted": "priceWhenPosted", + "news_publisher": "newsPublisher", + "news_base_url": "newsBaseURL", + "analyst_company": "analystCompany", + } + + @validator("publishedDate", pre=True, check_fields=False) + def published_date_validate(cls, v: str): # pylint: disable=E0213 + return datetime.strptime(v, "%Y-%m-%d") if v else None class FMPPriceTargetFetcher( @@ -57,6 +60,7 @@ class FMPPriceTargetFetcher( api_key = credentials.get("fmp_api_key") if credentials else "" url = create_url(4, "price-target", api_key, query) + return get_data_many(url, FMPPriceTargetData) @staticmethod diff --git a/openbb_sdk/sdk/provider/openbb_provider/models/price_target.py b/openbb_sdk/sdk/provider/openbb_provider/models/price_target.py index 8996090b42e..889c0b191c3 100644 --- a/openbb_sdk/sdk/provider/openbb_provider/models/price_target.py +++ b/openbb_sdk/sdk/provider/openbb_provider/models/price_target.py @@ -1,4 +1,4 @@ -"""Price target data model.""" +"""Price Target data model.""" from datetime import datetime @@ -8,54 +8,31 @@ from openbb_provider.abstract.data import Data from openbb_provider.abstract.query_params import QueryParams from openbb_provider.models.base import BaseSymbol +from pydantic import Field + class PriceTargetQueryParams(QueryParams, BaseSymbol): - """Price Target query. - - Parameter - --------- - symbol : str - The symbol of the company. - """ + """Price Target Query.""" class PriceTargetData(Data, BaseSymbol): - """Price target data. + """Price target Data.""" - Returns - ------- - symbol : str - The symbol of the asset. - published_date : datetime - The published date of the price target. - news_url : str - The news URL of the price target. - news_title : str - The news title of the price target. - analyst_name : str - The analyst name of the price target. - price_target : float - The price target of the price target. - adj_price_target : float - The adjusted price target of the price target. - price_when_posted : float - The price when posted of the price target. - news_publisher : str - The news publisher of the price target. - news_base_url : str - The news base URL of the price target. - analyst_company : str - The analyst company of the price target. - """ - - symbol: str - published_date: datetime - news_url: str - news_title: Optional[str] - analyst_name: Optional[str] - price_target: float - adj_price_target: float - price_when_posted: float - news_publisher: str - news_base_url: str - analyst_company: str + published_date: datetime = Field( + description="The published date of the price target." + ) + news_url: str = Field(description="The news URL of the price target.") + news_title: Optional[str] = Field(description="The news title of the price target.") + analyst_name: Optional[str] = Field( + description="The analyst name of the price target." + ) + price_target: float = Field(description="The price target of the price target.") + adj_price_target: float = Field( + description="The adjusted price target of the price target." + ) + price_when_posted: float = Field( + description="The price when posted of the price target." + ) + news_publisher: str = Field(description="The news publisher of the price target.") + news_base_url: str = Field(description="The news base URL of the price target.") + analyst_company: str = Field(description="The analyst company of the price target.")