Skip to content

Commit

Permalink
Merge pull request #1284 from ranaroussi/fix/financials-caching
Browse files Browse the repository at this point in the history
Improve caching of financials data
  • Loading branch information
ValueRaider committed Jan 12, 2023
2 parents 38637a9 + fd35975 commit 4db178b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion yfinance/scrapers/fundamentals.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def get_financials_time_series(self, timescale, keys: list, proxy=None) -> pd.Da
url = ts_url_base + "&type=" + ",".join([timescale + k for k in keys])
# Yahoo returns maximum 4 years or 5 quarters, regardless of start_dt:
start_dt = datetime.datetime(2016, 12, 31)
end = (datetime.datetime.now() + datetime.timedelta(days=366))
end = pd.Timestamp.utcnow().ceil("D")
url += "&period1={}&period2={}".format(int(start_dt.timestamp()), int(end.timestamp()))

# Step 3: fetch and reshape data
Expand Down
8 changes: 5 additions & 3 deletions yfinance/scrapers/quote.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,11 @@ def _scrape_complementary(self, proxy):
for k in keys:
url += "&type=" + k
# Request 6 months of data
url += "&period1={}".format(
int((datetime.datetime.now() - datetime.timedelta(days=365 // 2)).timestamp()))
url += "&period2={}".format(int((datetime.datetime.now() + datetime.timedelta(days=1)).timestamp()))
start = pd.Timestamp.utcnow().floor("D") - datetime.timedelta(days=365 // 2)
start = int(start.timestamp())
end = pd.Timestamp.utcnow().ceil("D")
end = int(end.timestamp())
url += f"&period1={start}&period2={end}"

json_str = self._data.cache_get(url=url, proxy=proxy).text
json_data = json.loads(json_str)
Expand Down

0 comments on commit 4db178b

Please sign in to comment.