Files
learn-trading/persistent_cache.py
T
tomatocream b5bf689e72 docs: add API references, mapping corrections, and verification script
- Add yfinance.org and defeatbeta-api.org reference docs
- Fix defeatbeta_mapping.org: deprecated yfinance property names
  (quarterly_financials→quarterly_income_stmt, financials→income_stmt),
  longName vs longBusinessSummary conceptual mismatch, cashflow note typo
- Add Mapping Limitations section with live verification results (AAPL):
  DuckDB 1.4.3 incompatibility, format differences, coverage gaps
- Add docs/test_mapping.py as runnable mapping verification script
- Add offline.py, persistent_cache.py, download_data.py, warmup_cache.py
  for offline/cached defeatbeta usage
- Add aapl_yfinance.py exploration script and quant.py scaffold
- Add .envrc (uv layout) and update pyproject.toml + uv.lock

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 15:33:21 +08:00

35 lines
1.1 KiB
Python

"""
Use the persistent defeatbeta httpfs cache at ~/.cache/defeatbeta/.
Import this at the top of any notebook or script before using Ticker().
Run warmup_cache.py once first to populate the cache.
from persistent_cache import enable_persistent_cache
enable_persistent_cache()
from defeatbeta_api.data.ticker import Ticker
t = Ticker("AAPL")
"""
from pathlib import Path
CACHE_DIR = Path.home() / ".cache" / "defeatbeta"
def enable_persistent_cache() -> None:
import defeatbeta_api.utils.util as _util
import defeatbeta_api.client.duckdb_client as _duckdb_mod
from defeatbeta_api.client.duckdb_conf import Configuration
if not CACHE_DIR.exists():
raise RuntimeError(
f"Cache directory not found: {CACHE_DIR}\n"
"Run warmup_cache.py first to populate it."
)
# Redirect cache directory to the persistent location
_util.validate_httpfs_cache_directory = lambda: str(CACHE_DIR)
# Reset singleton so DuckDB reinitialises pointing at the new cache dir
_duckdb_mod._instance = None
print(f"[persistent_cache] cache → {CACHE_DIR}")