Skip to content

Commit

Permalink
Add README section on tz-cache ; Add set_tz_cache_location()
Browse files Browse the repository at this point in the history
  • Loading branch information
ValueRaider committed Oct 23, 2022
1 parent ef12c8b commit f525ee2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
14 changes: 12 additions & 2 deletions README.md
Expand Up @@ -48,8 +48,6 @@ Yahoo! finance API is intended for personal use only.**

The `Ticker` module, which allows you to access ticker data in a more Pythonic way:

Note: yahoo finance datetimes are received as UTC.

```python
import yfinance as yf

Expand Down Expand Up @@ -214,6 +212,18 @@ data = yf.download( # or pdr.get_data_yahoo(...
)
```

### Timezone cache store

When fetching price data, all dates are localized to stock exchange timezone.
But timezone retrieval is relatively slow, so yfinance attemps to cache them
in your users cache folder.
You can direct cache to use a different location with `set_tz_cache_location()`:
```python
import yfinance as yf
yf.set_tz_cache_location("custom/cache/location")
...
```

### Managing Multi-Level Columns

The following answer on Stack Overflow is for [How to deal with
Expand Down
3 changes: 2 additions & 1 deletion yfinance/__init__.py
Expand Up @@ -23,6 +23,7 @@
from .ticker import Ticker
from .tickers import Tickers
from .multi import download
from .utils import set_tz_cache_location

__version__ = version.version
__author__ = "Ran Aroussi"
Expand All @@ -42,4 +43,4 @@ def pdr_override():
pass


__all__ = ['download', 'Ticker', 'Tickers', 'pdr_override']
__all__ = ['download', 'Ticker', 'Tickers', 'pdr_override', 'set_tz_cache_location']
10 changes: 9 additions & 1 deletion yfinance/utils.py
Expand Up @@ -316,8 +316,16 @@ def __str__(self):


# Simple file cache of ticker->timezone:
_cache_dp = None
def get_cache_dirpath():
return _os.path.join(_ad.user_cache_dir(), "py-yfinance")
if _cache_dp is None:
dp = _os.path.join(_ad.user_cache_dir(), "py-yfinance")
else:
dp = _os.path.join(_cache_dp, "py-yfinance")
def set_tz_cache_location(dp):
global _cache_dp
_cache_dp = dp

def cache_lookup_tkr_tz(tkr):
fp = _os.path.join(get_cache_dirpath(), "tkr-tz.csv")
if not _os.path.isfile(fp):
Expand Down

0 comments on commit f525ee2

Please sign in to comment.