diff --git a/openbb_sdk/providers/cboe/openbb_cboe/models/options_chains.py b/openbb_sdk/providers/cboe/openbb_cboe/models/options_chains.py index 9ad80b4fe0c..5afcc22426b 100644 --- a/openbb_sdk/providers/cboe/openbb_cboe/models/options_chains.py +++ b/openbb_sdk/providers/cboe/openbb_cboe/models/options_chains.py @@ -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.", ) diff --git a/openbb_sdk/providers/cboe/openbb_cboe/models/stock_search.py b/openbb_sdk/providers/cboe/openbb_cboe/models/stock_search.py index fa9d3c7ffe5..c227945296b 100644 --- a/openbb_sdk/providers/cboe/openbb_cboe/models/stock_search.py +++ b/openbb_sdk/providers/cboe/openbb_cboe/models/stock_search.py @@ -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", ) diff --git a/openbb_sdk/providers/fmp/openbb_fmp/models/balance_sheet_growth.py b/openbb_sdk/providers/fmp/openbb_fmp/models/balance_sheet_growth.py index 883024a6606..3f4edd3cde5 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/balance_sheet_growth.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/balance_sheet_growth.py @@ -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.""" diff --git a/openbb_sdk/providers/fmp/openbb_fmp/models/income_statement_growth.py b/openbb_sdk/providers/fmp/openbb_fmp/models/income_statement_growth.py index 61ffee7e1a0..b37cc6ee510 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/income_statement_growth.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/income_statement_growth.py @@ -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.""" diff --git a/openbb_sdk/providers/fmp/openbb_fmp/models/major_indices_eod.py b/openbb_sdk/providers/fmp/openbb_fmp/models/major_indices_eod.py index e6d41252685..8a4f0d81dd9 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/major_indices_eod.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/major_indices_eod.py @@ -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( 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 e47caca3fab..a33e46440fe 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/price_target.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/price_target.py @@ -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( diff --git a/openbb_sdk/providers/fmp/openbb_fmp/models/stock_insider_trading.py b/openbb_sdk/providers/fmp/openbb_fmp/models/stock_insider_trading.py index 3c7ed537411..41201f9aed9 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/stock_insider_trading.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/stock_insider_trading.py @@ -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[ diff --git a/openbb_sdk/providers/fmp/openbb_fmp/models/stock_quote.py b/openbb_sdk/providers/fmp/openbb_fmp/models/stock_quote.py index 1ddddd004f2..ef2b2d61a27 100644 --- a/openbb_sdk/providers/fmp/openbb_fmp/models/stock_quote.py +++ b/openbb_sdk/providers/fmp/openbb_fmp/models/stock_quote.py @@ -28,8 +28,6 @@ class FMPStockQuoteData(StockQuoteData): """Pydantic alias config using fields dict.""" fields = { - "price_avg50": "priceAvg50", - "price_avg200": "priceAvg200", "date": "timestamp", } diff --git a/openbb_sdk/sdk/provider/openbb_provider/abstract/data.py b/openbb_sdk/sdk/provider/openbb_provider/abstract/data.py index 2d6fd21acde..f7fdfb19ac8 100644 --- a/openbb_sdk/sdk/provider/openbb_provider/abstract/data.py +++ b/openbb_sdk/sdk/provider/openbb_provider/abstract/data.py @@ -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 diff --git a/openbb_sdk/sdk/provider/openbb_provider/standard_models/options_chains.py b/openbb_sdk/sdk/provider/openbb_provider/standard_models/options_chains.py index 9b1a884ceed..f39c252c745 100644 --- a/openbb_sdk/sdk/provider/openbb_provider/standard_models/options_chains.py +++ b/openbb_sdk/sdk/provider/openbb_provider/standard_models/options_chains.py @@ -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.") diff --git a/openbb_sdk/sdk/provider/openbb_provider/standard_models/price_target.py b/openbb_sdk/sdk/provider/openbb_provider/standard_models/price_target.py index 0c5ec275c24..cb7955ed1ee 100644 --- a/openbb_sdk/sdk/provider/openbb_provider/standard_models/price_target.py +++ b/openbb_sdk/sdk/provider/openbb_provider/standard_models/price_target.py @@ -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." + ) diff --git a/openbb_sdk/sdk/provider/openbb_provider/utils/helpers.py b/openbb_sdk/sdk/provider/openbb_provider/utils/helpers.py index 55cbba68397..54524750b9d 100644 --- a/openbb_sdk/sdk/provider/openbb_provider/utils/helpers.py +++ b/openbb_sdk/sdk/provider/openbb_provider/utils/helpers.py @@ -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