Skip to content

[BugFix] Fix yFinance Intraday "end_date" Filter #7059

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

Merged
merged 1 commit into from
Mar 12, 2025
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 @@ -511,8 +511,7 @@ def yf_download( # pylint: disable=too-many-positional-arguments
) -> "DataFrame":
"""Get yFinance OHLC data for any ticker and interval available."""
# pylint: disable=import-outside-toplevel
from datetime import datetime # noqa
from dateutil.relativedelta import relativedelta
from datetime import datetime, timedelta # noqa
from openbb_core.provider.utils.helpers import get_requests_session
from pandas import DataFrame, concat, to_datetime
import yfinance as yf
Expand All @@ -526,9 +525,7 @@ def yf_download( # pylint: disable=too-many-positional-arguments
intraday = True

if interval in ["2m", "5m", "15m", "30m", "90m"]:
_start_date = (datetime.now().date() - relativedelta(days=58)).strftime(
"%Y-%m-%d"
)
_start_date = (datetime.now().date() - timedelta(days=58)).strftime("%Y-%m-%d")
intraday = True

if interval == "1m":
Expand Down Expand Up @@ -591,6 +588,7 @@ def yf_download( # pylint: disable=too-many-positional-arguments
data = data.rename(columns={"Date": "date", "Datetime": "date"})
data["date"] = data["date"].apply(to_datetime)
data = data[data["Open"] > 0]

if start_date is not None:
data = data[data["date"] >= to_datetime(start_date)] # type: ignore
if (
Expand All @@ -602,7 +600,7 @@ def yf_download( # pylint: disable=too-many-positional-arguments
data["date"]
<= (
to_datetime(end_date) # type: ignore
+ relativedelta(minutes=719 if intraday is True else 0)
+ timedelta(days=1 if intraday is True else 0)
)
]
if intraday is True:
Expand Down
Loading