"""Regulatory data: CFTC COT reports, SEC litigation, institutional data.""" import asyncio import logging from typing import Any from openbb import obb from obb_utils import to_list logger = logging.getLogger(__name__) async def get_cot(symbol: str) -> list[dict[str, Any]]: """Get Commitment of Traders report for a futures symbol.""" try: result = await asyncio.to_thread( obb.regulators.cftc.cot, symbol, provider="cftc" ) return to_list(result) except Exception: logger.warning("COT failed for %s", symbol, exc_info=True) return [] async def cot_search(query: str) -> list[dict[str, Any]]: """Search COT report symbols.""" try: result = await asyncio.to_thread( obb.regulators.cftc.cot_search, query, provider="cftc" ) return to_list(result) except Exception: logger.warning("COT search failed for %s", query, exc_info=True) return [] async def get_sec_litigation() -> list[dict[str, Any]]: """Get SEC litigation releases.""" try: result = await asyncio.to_thread( obb.regulators.sec.rss_litigation, provider="sec" ) return to_list(result) except Exception: logger.warning("SEC litigation failed", exc_info=True) return [] async def search_institutions(query: str) -> list[dict[str, Any]]: """Search for institutional investors filing with SEC.""" try: result = await asyncio.to_thread( obb.regulators.sec.institutions_search, query, provider="sec" ) return to_list(result) except Exception: logger.warning("Institution search failed for %s", query, exc_info=True) return [] async def get_cik_map(symbol: str) -> list[dict[str, Any]]: """Map ticker symbol to CIK number.""" try: result = await asyncio.to_thread( obb.regulators.sec.cik_map, symbol, provider="sec" ) return to_list(result) except Exception: logger.warning("CIK map failed for %s", symbol, exc_info=True) return []