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.
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""Routes for regulatory data (CFTC, SEC)."""
|
|
|
|
from fastapi import APIRouter, Path, Query
|
|
|
|
from models import ApiResponse
|
|
from route_utils import safe, validate_symbol
|
|
import regulators_service
|
|
|
|
router = APIRouter(prefix="/api/v1/regulators")
|
|
|
|
|
|
@router.get("/cot", response_model=ApiResponse)
|
|
@safe
|
|
async def cot_report(symbol: str = Query(..., min_length=1, max_length=20)):
|
|
"""Commitment of Traders: commercial/speculator positions for futures."""
|
|
symbol = validate_symbol(symbol)
|
|
data = await regulators_service.get_cot(symbol)
|
|
return ApiResponse(data=data)
|
|
|
|
|
|
@router.get("/cot/search", response_model=ApiResponse)
|
|
@safe
|
|
async def cot_search(query: str = Query(..., min_length=1, max_length=100)):
|
|
"""Search COT report symbols."""
|
|
data = await regulators_service.cot_search(query)
|
|
return ApiResponse(data=data)
|
|
|
|
|
|
@router.get("/sec/litigation", response_model=ApiResponse)
|
|
@safe
|
|
async def sec_litigation():
|
|
"""SEC litigation releases RSS feed."""
|
|
data = await regulators_service.get_sec_litigation()
|
|
return ApiResponse(data=data)
|
|
|
|
|
|
@router.get("/sec/institutions", response_model=ApiResponse)
|
|
@safe
|
|
async def sec_institutions(query: str = Query(..., min_length=1, max_length=100)):
|
|
"""Search institutional investors filing with SEC."""
|
|
data = await regulators_service.search_institutions(query)
|
|
return ApiResponse(data=data)
|
|
|
|
|
|
@router.get("/sec/cik-map/{symbol}", response_model=ApiResponse)
|
|
@safe
|
|
async def sec_cik_map(symbol: str = Path(..., min_length=1, max_length=20)):
|
|
"""Map ticker symbol to SEC CIK number."""
|
|
symbol = validate_symbol(symbol)
|
|
data = await regulators_service.get_cik_map(symbol)
|
|
return ApiResponse(data=data)
|