-
Notifications
You must be signed in to change notification settings - Fork 130
[WIP][DO NOT MERGE] Historical data cache #254
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
base: master
Are you sure you want to change the base?
Conversation
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: - Only optimizes message count when querying newer data for the historical prices endpoint. 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: - Discuss the approach. - Add documentation on how to use. - Document the use-cases/limitations of the historical cache. Extra changes: - Added typing to get_historical_data. This was only done because it was the original point of entry in my work and I can reverse this.
|
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 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 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:
|
|
|
||
| def _execute_iex_query(self, url): | ||
| if len(self.symbols) > 1: | ||
| raise InternalError("Not supported yet") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic can go in the constructor after super
| result = result.loc[:, ["close", "volume"]] | ||
| return result | ||
|
|
||
| def _get_historical_data(self, symbol, start, end): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use fetch in the parent class instead of this method?
| symbol, start=start, end=end, close_only=self.close_only, **self.kwargs | ||
| ).fetch() | ||
|
|
||
| def _get_historical_data_cached(self, symbol): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fetch for the subclass.
| cache_type: CacheType = CacheType.NO_CACHE | ||
|
|
||
| def prepare_cache(cache: Union[CacheMetadata, pd.HDFStore]): | ||
| global _IEXFINANCE_CACHE_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment about global variables
Current Usage:
Current limitations:
for the historical prices endpoint.
I looked at how the
requests-cachemodule handles a globalvariables/sessions, but it can not apply in the case
of iexfinance (without refactoring) because
requests-cachemakes use of
requests's global session, so a globalvariable is used here instead.
TODOs:
Extra changes:
Added typing to get_historical_data. This was only
done because it was the original point of entry in my
work and I can reverse this.
closes #xxxx
tests added / passed
passes
black iexfinancepasses
git diff upstream/master -u -- "*.py" | flake8 --diffadded entry to docs/source/whatsnew/vLATEST.txt