Skip to content

Commit

Permalink
[BugFix] Return FMP Error Messages (#6237)
Browse files Browse the repository at this point in the history
* response callback and equity quote

* merge branch develop

* fix some more

* static files

* test param

* executive comp

* some more fetchers

* test cassette

* black

* another one

* some more

* etf equity exposure

* price_performance

* black

* ruff

* test params

* more test params

---------

Co-authored-by: Igor Radovanovic <74266147+IgorWounds@users.noreply.github.com>
  • Loading branch information
deeleeramone and IgorWounds authored Mar 21, 2024
1 parent bb6efdf commit 78695fa
Show file tree
Hide file tree
Showing 28 changed files with 1,094 additions and 882 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Analyst Estimates Standard Model."""

from datetime import date as dateType
from typing import List, Literal, Optional, Set, Union
from typing import Optional

from pydantic import Field, field_validator

Expand All @@ -17,68 +17,76 @@ class AnalystEstimatesQueryParams(QueryParams):
"""Analyst Estimates Query."""

symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", ""))
period: Literal["quarter", "annual"] = Field(
default="annual", description=QUERY_DESCRIPTIONS.get("period", "")
)
limit: int = Field(default=30, description=QUERY_DESCRIPTIONS.get("limit", ""))

@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def to_upper(cls, v: str) -> str:
"""Convert field to uppercase."""
return v.upper()

@field_validator("period", mode="before", check_fields=False)
@classmethod
def to_lower(cls, v: Optional[str]) -> Optional[str]:
"""Convert field to lowercase."""
return v.lower() if v else v


class AnalystEstimatesData(Data):
"""Analyst Estimates data."""

symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
estimated_revenue_low: ForceInt = Field(description="Estimated revenue low.")
estimated_revenue_high: ForceInt = Field(description="Estimated revenue high.")
estimated_revenue_avg: ForceInt = Field(description="Estimated revenue average.")
estimated_ebitda_low: ForceInt = Field(description="Estimated EBITDA low.")
estimated_ebitda_high: ForceInt = Field(description="Estimated EBITDA high.")
estimated_ebitda_avg: ForceInt = Field(description="Estimated EBITDA average.")
estimated_ebit_low: ForceInt = Field(description="Estimated EBIT low.")
estimated_ebit_high: ForceInt = Field(description="Estimated EBIT high.")
estimated_ebit_avg: ForceInt = Field(description="Estimated EBIT average.")
estimated_net_income_low: ForceInt = Field(description="Estimated net income low.")
estimated_net_income_high: ForceInt = Field(
description="Estimated net income high."
)
estimated_net_income_avg: ForceInt = Field(
description="Estimated net income average."
)
estimated_sga_expense_low: ForceInt = Field(
description="Estimated SGA expense low."
)
estimated_sga_expense_high: ForceInt = Field(
description="Estimated SGA expense high."
)
estimated_sga_expense_avg: ForceInt = Field(
description="Estimated SGA expense average."
)
estimated_eps_avg: float = Field(description="Estimated EPS average.")
estimated_eps_high: float = Field(description="Estimated EPS high.")
estimated_eps_low: float = Field(description="Estimated EPS low.")
number_analyst_estimated_revenue: ForceInt = Field(
description="Number of analysts who estimated revenue."
)
number_analysts_estimated_eps: ForceInt = Field(
description="Number of analysts who estimated EPS."
estimated_revenue_low: Optional[ForceInt] = Field(
default=None, description="Estimated revenue low."
)
estimated_revenue_high: Optional[ForceInt] = Field(
default=None, description="Estimated revenue high."
)
estimated_revenue_avg: Optional[ForceInt] = Field(
default=None, description="Estimated revenue average."
)
estimated_sga_expense_low: Optional[ForceInt] = Field(
default=None, description="Estimated SGA expense low."
)
estimated_sga_expense_high: Optional[ForceInt] = Field(
default=None, description="Estimated SGA expense high."
)
estimated_sga_expense_avg: Optional[ForceInt] = Field(
default=None, description="Estimated SGA expense average."
)
estimated_ebitda_low: Optional[ForceInt] = Field(
default=None, description="Estimated EBITDA low."
)
estimated_ebitda_high: Optional[ForceInt] = Field(
default=None, description="Estimated EBITDA high."
)
estimated_ebitda_avg: Optional[ForceInt] = Field(
default=None, description="Estimated EBITDA average."
)
estimated_ebit_low: Optional[ForceInt] = Field(
default=None, description="Estimated EBIT low."
)
estimated_ebit_high: Optional[ForceInt] = Field(
default=None, description="Estimated EBIT high."
)
estimated_ebit_avg: Optional[ForceInt] = Field(
default=None, description="Estimated EBIT average."
)
estimated_net_income_low: Optional[ForceInt] = Field(
default=None, description="Estimated net income low."
)
estimated_net_income_high: Optional[ForceInt] = Field(
default=None, description="Estimated net income high."
)
estimated_net_income_avg: Optional[ForceInt] = Field(
default=None, description="Estimated net income average."
)
estimated_eps_avg: Optional[float] = Field(
default=None, description="Estimated EPS average."
)
estimated_eps_high: Optional[float] = Field(
default=None, description="Estimated EPS high."
)
estimated_eps_low: Optional[float] = Field(
default=None, description="Estimated EPS low."
)
number_analyst_estimated_revenue: Optional[ForceInt] = Field(
default=None, description="Number of analysts who estimated revenue."
)
number_analysts_estimated_eps: Optional[ForceInt] = Field(
default=None, description="Number of analysts who estimated EPS."
)

@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def to_upper(cls, v: Union[str, List[str], Set[str]]):
"""Convert field to uppercase."""
if isinstance(v, str):
return v.upper()
return ",".join([symbol.upper() for symbol in list(v)]) if v else None
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
"""Executive Compensation Standard Model."""

from datetime import (
date as dateType,
datetime,
)
from typing import List, Optional, Set, Union
from typing import Optional

from pydantic import Field, NonNegativeFloat, field_validator

Expand All @@ -20,14 +16,6 @@ class ExecutiveCompensationQueryParams(QueryParams):
"""Executive Compensation Query."""

symbol: str = Field(description=QUERY_DESCRIPTIONS.get("symbol", ""))
start_date: Optional[dateType] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("start_date", ""),
)
end_date: Optional[dateType] = Field(
default=None,
description=QUERY_DESCRIPTIONS.get("end_date", ""),
)

@field_validator("symbol", mode="before", check_fields=False)
@classmethod
Expand All @@ -41,29 +29,31 @@ class ExecutiveCompensationData(Data):

symbol: str = Field(description=DATA_DESCRIPTIONS.get("symbol", ""))
cik: Optional[str] = Field(
default=None,
description=DATA_DESCRIPTIONS.get("cik", ""),
default=None, description=DATA_DESCRIPTIONS.get("cik", "")
)
filing_date: dateType = Field(description="Date of the filing.")
accepted_date: datetime = Field(description="Date the filing was accepted.")
name_and_position: str = Field(description="Name and position of the executive.")
year: int = Field(description="Year of the compensation.")
salary: NonNegativeFloat = Field(description="Salary of the executive.")
bonus: NonNegativeFloat = Field(description="Bonus of the executive.")
stock_award: NonNegativeFloat = Field(description="Stock award of the executive.")
incentive_plan_compensation: NonNegativeFloat = Field(
description="Incentive plan compensation of the executive."
company_name: Optional[str] = Field(
default=None, description="The name of the company."
)
all_other_compensation: NonNegativeFloat = Field(
description="All other compensation of the executive."
industry: Optional[str] = Field(
default=None, description="The industry of the company."
)
year: Optional[int] = Field(default=None, description="Year of the compensation.")
name_and_position: Optional[str] = Field(
default=None, description="Name and position."
)
salary: Optional[NonNegativeFloat] = Field(default=None, description="Salary.")
bonus: Optional[NonNegativeFloat] = Field(
default=None, description="Bonus payments."
)
stock_award: Optional[NonNegativeFloat] = Field(
default=None, description="Stock awards."
)
incentive_plan_compensation: Optional[NonNegativeFloat] = Field(
default=None, description="Incentive plan compensation."
)
all_other_compensation: Optional[NonNegativeFloat] = Field(
default=None, description="All other compensation."
)
total: Optional[NonNegativeFloat] = Field(
default=None, description="Total compensation."
)
total: NonNegativeFloat = Field(description="Total compensation of the executive.")
url: str = Field(description="URL of the filing data.")

@field_validator("symbol", mode="before", check_fields=False)
@classmethod
def to_upper(cls, v: Union[str, List[str], Set[str]]):
"""Convert field to uppercase."""
if isinstance(v, str):
return v.upper()
return ",".join([symbol.upper() for symbol in list(v)])
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Historical Splits Standard Model."""

from datetime import date as dateType
from typing import Optional

from pydantic import Field, field_validator

Expand Down Expand Up @@ -28,8 +29,15 @@ class HistoricalSplitsData(Data):
"""Historical Splits Data."""

date: dateType = Field(description=DATA_DESCRIPTIONS.get("date", ""))
label: str = Field(description="Label of the historical stock splits.")
numerator: float = Field(description="Numerator of the historical stock splits.")
denominator: float = Field(
description="Denominator of the historical stock splits."
numerator: Optional[float] = Field(
default=None,
description="Numerator of the split.",
)
denominator: Optional[float] = Field(
default=None,
description="Denominator of the split.",
)
split_ratio: Optional[str] = Field(
default=None,
description="Split ratio.",
)
Original file line number Diff line number Diff line change
Expand Up @@ -235,21 +235,22 @@ def test_equity_fundamental_cash_growth(params, headers):
(
{
"symbol": "AAPL",
"start_date": "2020-01-01",
"end_date": "2021-01-01",
"year": 2022,
"provider": "fmp",
}
),
(
{
"symbol": "AAPL",
"provider": "fmp",
"year": None,
}
),
(
{
"symbol": "AAPL,MSFT",
"provider": "fmp",
"year": None,
}
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,21 +217,22 @@ def test_equity_fundamental_cash_growth(params, obb):
(
{
"symbol": "AAPL",
"start_date": "2020-01-01",
"end_date": "2021-01-01",
"year": 2022,
"provider": "fmp",
}
),
(
{
"symbol": "AAPL",
"provider": "fmp",
"year": None,
}
),
(
{
"symbol": "AAPL,MSFT",
"provider": "fmp",
"year": None,
}
),
],
Expand Down
Loading

0 comments on commit 78695fa

Please sign in to comment.