"""Equity shorts and dark pool data (stockgrid, FINRA, SEC).""" 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_short_volume(symbol: str) -> list[dict[str, Any]]: """Get daily short volume data (stockgrid).""" try: result = await asyncio.to_thread( obb.equity.shorts.short_volume, symbol, provider="stockgrid" ) return to_list(result) except Exception: logger.warning("Short volume failed for %s", symbol, exc_info=True) return [] async def get_fails_to_deliver(symbol: str) -> list[dict[str, Any]]: """Get fails-to-deliver records (SEC).""" try: result = await asyncio.to_thread( obb.equity.shorts.fails_to_deliver, symbol, provider="sec" ) return to_list(result) except Exception: logger.warning("FTD failed for %s", symbol, exc_info=True) return [] async def get_short_interest(symbol: str) -> list[dict[str, Any]]: """Get short interest positions (FINRA).""" try: result = await asyncio.to_thread( obb.equity.shorts.short_interest, symbol, provider="finra" ) return to_list(result) except Exception: logger.warning("Short interest failed for %s", symbol, exc_info=True) return [] async def get_darkpool_otc(symbol: str) -> list[dict[str, Any]]: """Get OTC/dark pool aggregate trade data (FINRA).""" try: result = await asyncio.to_thread( obb.equity.darkpool.otc, symbol, provider="finra" ) return to_list(result) except Exception: logger.warning("Dark pool OTC failed for %s", symbol, exc_info=True) return []