Requests caching not working for history data #1575
-
Hey everyone I try to cache the requests to the yahoo API as described in the readme file. Here is a minimum example: import yfinance as yf
import requests_cache
from pandas_datareader import data as pdr
from requests import Session
from requests_cache import CacheMixin, SQLiteCache
from requests_ratelimiter import LimiterMixin, MemoryQueueBucket
from pyrate_limiter import Duration, RequestRate, Limiter
class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
pass
#yf.enable_debug_mode()
session = CachedLimiterSession(
limiter=Limiter(RequestRate(2, Duration.SECOND*5), # max 2 requests per 5 seconds
bucket_class=MemoryQueueBucket),
backend=SQLiteCache("yfinance.cache"),
)
ticker = yf.Ticker('EBAY', session=session)
df = ticker.history(period='max')
print(ticker.info['longName'])
print(df.head()) With WIFI activated, it creates this output:
And deactivated WIFI this output:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
yfinance only caches if a request is guaranteed to return same data regardless of time, e.g. yesterday. |
Beta Was this translation helpful? Give feedback.
yfinance only caches if a request is guaranteed to return same data regardless of time, e.g. yesterday.
max
is not 100% in past, and yfinance not smart enough to detect if market closed (maybe it could be ...)