"""WarehouseLivePrice — a LivePrice backed by the LATEST warehouse close, for the Bybit live paper book's
mark-to-market. The legacy-venue live view used a public-REST price source (BTC/ETH only); the Bybit book
holds many alt symbols whose live mark is the latest Bybit-perp close already in `bybit_features`. This adapter
serves `{symbol: latest_close}` for ONLY the requested symbols (a `WHERE symbol IN (...)` read — bounded by
the open book, not the whole table). READ-ONLY; never raises on a read hiccup (degrades to {} → the view
marks at entry), so it never 500s the cockpit."""
from __future__ import annotations

import logging
from typing import Any

_log = logging.getLogger(__name__)


class WarehouseLivePrice:
    def __init__(self, store: Any) -> None:
        self._store = store

    def get_prices(self, symbols: list[str]) -> dict[str, float]:
        if not symbols:
            return {}
        try:
            # LATEST close per symbol via a per-symbol index seek — NOT the full-history panel. The old
            # read_panel pulled the entire multi-year close history of every open-book symbol (~21k rows /
            # ~0.5s) just to take the last value; read_latest returns one row per symbol (~1ms). This was the
            # /paper + /paper/live (45s) latency hotspot.
            return self._store.read_latest(list(symbols), "close")
        except Exception as exc:  # noqa: BLE001 — a read hiccup must never 500 the page
            _log.warning("WarehouseLivePrice read failed, marking at entry: %s", exc)
            return {}
