from __future__ import annotations import time from threading import Lock from typing import Optional _lock = Lock() _prices: dict[str, tuple[float, float]] = {} def prime(symbol: str, price_usd: float, ttl_sec: float = 300) -> None: if not price_usd or price_usd <= 0: return key = symbol.upper() with _lock: _prices[key] = (price_usd, time.time() + ttl_sec) def get(symbol: str) -> Optional[float]: key = symbol.upper() with _lock: row = _prices.get(key) if not row: return None price, expires = row if expires <= time.time(): return None return price def snapshot() -> dict[str, float]: now = time.time() with _lock: return {k: v[0] for k, v in _prices.items() if v[1] > now}