Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BugFix] yFinance ETF Info: Try Different Field When Missing fundInceptionDate #6260

Merged
merged 5 commits into from
Mar 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -249,6 +251,7 @@ async def aextract_data(
"fiveYearAverageReturn",
"beta3Year",
"longBusinessSummary",
"firstTradeDateEpochUtc",
]

async def get_one(symbol):
Expand All @@ -262,9 +265,22 @@ async def get_one(symbol):
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:
Expand Down
Loading