Prerequisite refactor: - Consolidate duplicate _to_dicts into shared obb_utils.to_list - Add fetch_historical and first_or_empty helpers to obb_utils Phase 1 - Local computation (no provider risk): - Group I: 12 technical indicators (ATR, ADX, Stoch, OBV, Ichimoku, Donchian, Aroon, CCI, Keltner, Fibonacci, A/D, Volatility Cones) - Group J: Sortino, Omega ratios + rolling stats (variance, stdev, mean, skew, kurtosis, quantile via generic endpoint) - Group H: ECB currency reference rates Phase 2 - FRED/Federal Reserve providers: - Group C: 10 fixed income endpoints (treasury rates, yield curve, auctions, TIPS, EFFR, SOFR, HQM, commercial paper, spot rates, spreads) - Group D: 11 economy endpoints (CPI, GDP, unemployment, PCE, money measures, CLI, HPI, FRED search, balance of payments, Fed holdings, FOMC documents) - Group E: 5 survey endpoints (Michigan, SLOOS, NFP, Empire State, BLS search) Phase 3 - SEC/stockgrid/FINRA providers: - Group B: 4 equity fundamental endpoints (management, dividends, SEC filings, company search) - Group A: 4 shorts/dark pool endpoints (short volume, FTD, short interest, OTC dark pool) - Group F: 3 index/ETF enhanced (S&P 500 multiples, index constituents, ETF N-PORT) Phase 4 - Regulators: - Group G: 5 regulatory endpoints (COT report, COT search, SEC litigation, institution search, CIK mapping) Security hardening: - Service-layer allowlists for all getattr dynamic dispatch - Regex validation on date, country, security_type, form_type params - Exception handling in fetch_historical - Callable guard on rolling stat dispatch Total: 32 existing + 67 new = 99 endpoints, all free providers.
60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
"""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 []
|