diff options
author | Danglewood <85772166+deeleeramone@users.noreply.github.com> | 2024-03-30 07:32:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-30 14:32:32 +0000 |
commit | 42a8c8f790aedf5aae7bbcb0fd9eeefebc897cfa (patch) | |
tree | 4b75bdb62b13cdf3dc9d9a73188f14faa19bbf65 | |
parent | 76405567e5cc91b19d3508592bff61b035ac7660 (diff) |
[BugFix] yFinance ETF Info: Try Different Field When Missing fundInceptionDate (#6260)
* try different field when missing the inceptionDate
* wrap that in try-except
* pylint
-rw-r--r-- | openbb_platform/providers/yfinance/openbb_yfinance/models/etf_info.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/openbb_platform/providers/yfinance/openbb_yfinance/models/etf_info.py b/openbb_platform/providers/yfinance/openbb_yfinance/models/etf_info.py index 546ee9c8fb3..c2ce1a28355 100644 --- a/openbb_platform/providers/yfinance/openbb_yfinance/models/etf_info.py +++ b/openbb_platform/providers/yfinance/openbb_yfinance/models/etf_info.py @@ -190,7 +190,9 @@ class YFinanceEtfInfoData(EtfInfoData): @classmethod def validate_date(cls, v): """Validate first stock price date.""" - return datetime.utcfromtimestamp(v).date().strftime("%Y-%m-%d") if v else None + if isinstance(v, datetime): + return v.date().strftime("%Y-%m-%d") + return datetime.fromtimestamp(v).date().strftime("%Y-%m-%d") if v else None class YFinanceEtfInfoFetcher( @@ -249,6 +251,7 @@ class YFinanceEtfInfoFetcher( "fiveYearAverageReturn", "beta3Year", "longBusinessSummary", + "firstTradeDateEpochUtc", ] async def get_one(symbol): @@ -262,9 +265,22 @@ class YFinanceEtfInfoFetcher( if ticker: quote_type = ticker.pop("quoteType", "") if quote_type == "ETF": - for field in fields: - if field in ticker: - result[field] = ticker.get(field, None) + try: + for field in fields: + if field in ticker and ticker.get(field) is not None: + result[field] = ticker.get(field, None) + if "firstTradeDateEpochUtc" in result: + _first_trade = result.pop("firstTradeDateEpochUtc") + if ( + "fundInceptionDate" not in result + and _first_trade is not None + ): + result["fundInceptionDate"] = datetime.fromtimestamp( + _first_trade + ) + except Exception as e: + _warn(f"Error processing data for {symbol}: {e}") + result = {} if quote_type != "ETF": _warn(f"{symbol} is not an ETF.") if result: |