addisonlynch / iexfinance

Python SDK for IEX Cloud
https://addisonlynch.github.io/iexfinance
Apache License 2.0
648 stars 136 forks source link

[WIP][DO NOT MERGE] Historical data cache #254

Open Olshansk opened 3 years ago

Olshansk commented 3 years ago

Current Usage:

from iexfinance.stocks.cache import *

prepare_cache(CacheMetadata(cache_path="store.h5", cache_type=CacheType.HDF_STORE))

get_historical_data(...)
get_historical_data(...)
get_historical_data(...)

Current limitations:

I looked at how the requests-cache module handles a global variables/sessions, but it can not apply in the case of iexfinance (without refactoring) because requests-cache makes use of requests's global session, so a global variable is used here instead.

TODOs:

Extra changes:

addisonlynch commented 3 years ago

Initial thoughts. Going to take a more in-depth look early this week.

Looks good!

What are your thoughts about allowing the user to pass the cache as an argument to get_historical_data rather than using global variables?

e.g.

cache = prepare_cache(CacheMetadata(cache_path="store.h5", cache_type=CacheType.HDF_STORE))
get_historical_data("AAPL", start=start, end=end, cache=cache)

and then some logic in get_historical_data:

if cache is not None:
    return HistoricalReaderCache(
        symbols, start=start, end=end, close_only=close_only, cache=cache **kwargs
    ).fetch()
else:
   return HistoricalReader(
        symbols, start=start, end=end, close_only=close_only, **kwargs
    ).fetch()

Trivial: