Initial public release
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
"""Force-refresh per-exchange EODHD symbol-list cache.
|
||||
|
||||
The TickerResolver and USD-returns builder both read from
|
||||
``data/raw/eodhd/symbols/{EX}_active.json`` to map (a) BR tickers -> EODHD
|
||||
codes and (b) tickers -> trading currency. ``EODHDClient.get_exchange_symbols``
|
||||
uses ``use_cache=True`` in every production call site, which means once those
|
||||
JSONs are on disk they are NEVER refetched — a new index constituent (IPO,
|
||||
listing change) that postdates the cache silently drops out of the universe
|
||||
and/or the USD panel.
|
||||
|
||||
This script bypasses the cache and refetches every gated exchange. Cheap:
|
||||
19 exchanges × 1 API call each, ~10 s wall-clock and a trivial quota hit.
|
||||
Invoked as step 1/9 of the monthly orchestrator so the cache is always
|
||||
current at signal time.
|
||||
|
||||
Output: ``data/raw/eodhd/symbols/{EX}_active.json`` (overwritten in place).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent.parent)) # noqa: E402
|
||||
|
||||
from src.data import GATED_EXCHANGES
|
||||
from src.data.eodhd_client import EODHDClient, EODHDError
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s %(levelname)s %(name)s — %(message)s",
|
||||
datefmt="%Y-%m-%dT%H:%M:%S",
|
||||
)
|
||||
logger = logging.getLogger("refresh_symbol_cache")
|
||||
|
||||
|
||||
def main() -> None:
|
||||
client = EODHDClient()
|
||||
total = 0
|
||||
for ex in GATED_EXCHANGES:
|
||||
try:
|
||||
df = client.get_exchange_symbols(ex, delisted=False, use_cache=False)
|
||||
except EODHDError as exc:
|
||||
logger.error("Refresh failed for %s: %s", ex, exc)
|
||||
sys.exit(1)
|
||||
n = len(df)
|
||||
total += n
|
||||
logger.info("Refreshed %s: %d symbols", ex, n)
|
||||
logger.info(
|
||||
"Refreshed %d exchanges, %d total symbol rows", len(GATED_EXCHANGES), total
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user