Fix snake case (#5404)

* change abstract data

* cboe

* fmp
This commit is contained in:
montezdesousa
2023-09-03 13:33:05 +01:00
committed by GitHub
parent e3a0ae4b5a
commit 35f5637543
12 changed files with 66 additions and 51 deletions

View File

@@ -24,19 +24,19 @@ class CboeOptionsChainsQueryParams(OptionsChainsQueryParams):
class CboeOptionsChainsData(OptionsChainsData):
"""CBOE Options Chains Data."""
contractSymbol: str = Field(
contract_symbol: str = Field(
description="Contract symbol for the option.",
)
dte: int = Field(
description="Days to expiration for the option.",
)
bidSize: int = Field(
bid_size: int = Field(
description="Bid size for the option.",
)
askSize: int = Field(
ask_size: int = Field(
description="Ask size for the option.",
)
impliedVolatility: float = Field(
implied_volatility: float = Field(
description="Implied volatility of the option.",
)
delta: float = Field(
@@ -66,22 +66,22 @@ class CboeOptionsChainsData(OptionsChainsData):
low: float = Field(
description="Low price of the option.",
)
lastTradePrice: float = Field(
last_trade_price: float = Field(
description="Last trade price of the option.",
)
tick: str = Field(
description="Whether the last tick was up or down in price.",
)
previousClose: float = Field(
previous_close: float = Field(
description="Previous closing price of the option.",
)
change: float = Field(
description="Change in price of the option.",
)
changePercent: float = Field(
change_percent: float = Field(
description="Change, in percent, of the option.",
)
lastTradeTimestamp: datetime = Field(
last_trade_timestamp: datetime = Field(
description="Last trade timestamp of the option.",
)

View File

@@ -30,11 +30,11 @@ class CboeStockSearchData(StockSearchData):
"name": "Company Name",
}
dpmName: Optional[str] = Field(
dpm_name: Optional[str] = Field(
description="Name of the primary market maker.",
alias="DPM Name",
)
postStation: Optional[str] = Field(
post_station: Optional[str] = Field(
description="Post and station location on the CBOE trading floor.",
alias="Post/Station",
)

View File

@@ -24,13 +24,6 @@ class FMPBalanceSheetGrowthQueryParams(BalanceSheetGrowthQueryParams):
class FMPBalanceSheetGrowthData(BalanceSheetGrowthData):
"""FMP Balance Sheet Growth Data."""
class Config:
"""Pydantic alias config using fields Dict."""
fields = {
"growth_deferred_tax_liabilities_non_current": "growthDeferrredTaxLiabilitiesNonCurrent",
}
@validator("date", pre=True, check_fields=False)
def date_validate(cls, v): # pylint: disable=E0213
"""Return the date as a datetime object."""

View File

@@ -24,6 +24,16 @@ class FMPIncomeStatementGrowthQueryParams(IncomeStatementGrowthQueryParams):
class FMPIncomeStatementGrowthData(IncomeStatementGrowthData):
"""FMP Income Statement Growth Data."""
class Config:
"""Pydantic alias config using fields dict."""
fields = {
"growth_ebitda": "growthEBITDA",
"growth_ebitda_ratio": "growthEBITDARatio",
"growth_eps": "growthEPS",
"growth_eps_diluted": "growthEPSDiluted",
}
@validator("date", pre=True, check_fields=False)
def date_validate(cls, v): # pylint: disable=E0213
"""Return the date as a datetime object."""

View File

@@ -32,11 +32,11 @@ class FMPMajorIndicesEODQueryParams(MajorIndicesEODQueryParams):
class FMPMajorIndicesEODData(MajorIndicesEODData):
"""FMP Major Indices end of day Data."""
adjClose: Optional[float] = Field(
adj_close: Optional[float] = Field(
description="Adjusted Close Price of the symbol.",
default=None,
)
unadjustedVolume: Optional[float] = Field(
unadjusted_volume: Optional[float] = Field(
description="Unadjusted volume of the symbol.",
default=None,
)
@@ -44,26 +44,25 @@ class FMPMajorIndicesEODData(MajorIndicesEODData):
description="Change in the price of the symbol from the previous day.",
default=None,
)
changePercent: Optional[float] = Field(
change_percent: Optional[float] = Field(
description=r"Change \% in the price of the symbol.",
default=None,
)
label: Optional[str] = Field(
description="Human readable format of the date.", default=None
)
changeOverTime: Optional[float] = Field(
change_over_time: Optional[float] = Field(
description=r"Change \% in the price of the symbol over a period of time.",
default=None,
)
@validator("date", pre=True)
def date_validate( # pylint: disable=E0213
cls, v, values: Dict[str, Any]
) -> datetime:
def date_validate(cls, v) -> datetime: # pylint: disable=E0213
"""Return the date as a datetime object."""
if values.get("changeOverTime", None) is not None:
return datetime.strptime(v, "%Y-%m-%d")
return datetime.strptime(v, "%Y-%m-%d %H:%M:%S")
# TODO: Check if this condition is necessary
# if values.get("changeOverTime", None) is not None:
# return datetime.strptime(v, "%Y-%m-%d")
return datetime.strptime(v, "%Y-%m-%d")
class FMPMajorIndicesEODFetcher(

View File

@@ -28,9 +28,14 @@ class FMPPriceTargetQueryParams(PriceTargetQueryParams):
class FMPPriceTargetData(PriceTargetData):
"""FMP Price Target Data."""
newGrade: Optional[str] = Field(alias="new_grade", default=None)
previousGrade: Optional[str] = Field(alias="previous_grade", default=None)
gradingCompany: Optional[str] = Field(alias="grading_company", default=None)
class Config:
"""Pydantic alias config using fields dict."""
fields = {"news_url": "newsURL", "news_base_url": "newsBaseURL"}
new_grade: Optional[str]
previous_grade: Optional[str]
grading_company: Optional[str]
class FMPPriceTargetFetcher(

View File

@@ -22,14 +22,6 @@ class FMPStockInsiderTradingQueryParams(StockInsiderTradingQueryParams):
class FMPStockInsiderTradingData(StockInsiderTradingData):
"""FMP Stock Insider Trading Data."""
class Config:
"""Pydantic alias config using fields dict."""
fields = {
"acquisition_or_disposition": "acquistionOrDisposition",
"last_number_of_13f_shares": "lastNumberOf13FShares",
}
class FMPStockInsiderTradingFetcher(
Fetcher[

View File

@@ -28,8 +28,6 @@ class FMPStockQuoteData(StockQuoteData):
"""Pydantic alias config using fields dict."""
fields = {
"price_avg50": "priceAvg50",
"price_avg200": "priceAvg200",
"date": "timestamp",
}

View File

@@ -1,7 +1,7 @@
"""The OpenBB Standardized Data Model."""
from pydantic import BaseModel, Extra
from openbb_provider.utils.helpers import to_snake_case
from openbb_provider.utils.helpers import to_camel_case, to_snake_case
class Data(BaseModel):
@@ -13,15 +13,11 @@ class Data(BaseModel):
def __repr__(self):
"""Return a string representation of the object."""
return f"{self.__class__.__name__}({', '.join([f'{k}={v}' for k, v in self.dict().items()])})"
return f"{self.__class__.__name__}({', '.join([f'{k}={v}' for k, v in super().dict().items()])})"
class Config:
"""Pydantic configuration."""
extra = Extra.allow
allow_population_by_field_name = True
def __init__(self, **data):
"""Initialize the model."""
data = {to_snake_case(k): v for k, v in data.items()}
super().__init__(**data)
alias_generator = to_camel_case

View File

@@ -18,8 +18,8 @@ class OptionsChainsData(Data):
expiration: datetime = Field(description="Expiration date of the contract.")
strike: float = Field(description="Strike price of the contract.")
optionType: str = Field(description="Call or Put.")
option_type: str = Field(description="Call or Put.")
bid: float = Field(description="Bid price of the contract.")
ask: float = Field(description="Ask price of the contract.")
openInterest: float = Field(description="Open interest on the contract.")
open_interest: float = Field(description="Open interest on the contract.")
volume: float = Field(description="Current trading volume on the contract.")

View File

@@ -26,5 +26,9 @@ class PriceTargetData(Data, BaseSymbol):
price_target: Optional[float] = Field(description="Price target.")
adj_price_target: Optional[float] = Field(description="Adjusted price target.")
price_when_posted: Optional[float] = Field(description="Price when posted.")
news_publisher: str = Field(description="News publisher of the price target.")
news_base_url: str = Field(description="News base URL of the price target.")
news_publisher: Optional[str] = Field(
description="News publisher of the price target."
)
news_base_url: Optional[str] = Field(
description="News base URL of the price target."
)

View File

@@ -107,3 +107,21 @@ def to_snake_case(string: str) -> str:
.replace(" ", "_")
.replace("__", "_")
)
def to_camel_case(string: str):
"""Convert a string to camel case. If all characters are lower case we return title
version of the string.
Examples
--------
"close" -> "Close"
"some_field" -> "someField"
"""
s_list = string.replace("-", " ").replace("_", " ").split()
if len(string) == 0:
return string
result = s_list[0] + "".join(i.capitalize() for i in s_list[1:])
if result.islower():
return result.title()
return result