feat: add 67 new endpoints across 10 feature groups
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.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""Routes for technical analysis indicators."""
|
||||
|
||||
from fastapi import APIRouter, Path
|
||||
from fastapi import APIRouter, Path, Query
|
||||
|
||||
from models import ApiResponse
|
||||
from route_utils import safe, validate_symbol
|
||||
@@ -16,3 +16,140 @@ async def stock_technical(symbol: str = Path(..., min_length=1, max_length=20)):
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_technical_indicators(symbol)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
# --- Individual Technical Indicators (Group I) ---
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/atr", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_atr(
|
||||
symbol: str = Path(..., min_length=1, max_length=20),
|
||||
length: int = Query(default=14, ge=1, le=100),
|
||||
):
|
||||
"""Average True Range -- volatility for position sizing and stop-loss."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_atr(symbol, length=length)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/adx", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_adx(
|
||||
symbol: str = Path(..., min_length=1, max_length=20),
|
||||
length: int = Query(default=14, ge=1, le=100),
|
||||
):
|
||||
"""Average Directional Index -- trend strength (>25 strong, <20 range-bound)."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_adx(symbol, length=length)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/stoch", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_stoch(
|
||||
symbol: str = Path(..., min_length=1, max_length=20),
|
||||
fast_k: int = Query(default=14, ge=1, le=100),
|
||||
slow_d: int = Query(default=3, ge=1, le=100),
|
||||
slow_k: int = Query(default=3, ge=1, le=100),
|
||||
):
|
||||
"""Stochastic Oscillator -- overbought/oversold momentum signal."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_stoch(symbol, fast_k=fast_k, slow_d=slow_d, slow_k=slow_k)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/obv", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_obv(symbol: str = Path(..., min_length=1, max_length=20)):
|
||||
"""On-Balance Volume -- cumulative volume for divergence detection."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_obv(symbol)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/ichimoku", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_ichimoku(symbol: str = Path(..., min_length=1, max_length=20)):
|
||||
"""Ichimoku Cloud -- comprehensive trend system with support/resistance."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_ichimoku(symbol)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/donchian", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_donchian(
|
||||
symbol: str = Path(..., min_length=1, max_length=20),
|
||||
length: int = Query(default=20, ge=1, le=100),
|
||||
):
|
||||
"""Donchian Channels -- breakout detection system."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_donchian(symbol, length=length)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/aroon", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_aroon(
|
||||
symbol: str = Path(..., min_length=1, max_length=20),
|
||||
length: int = Query(default=25, ge=1, le=100),
|
||||
):
|
||||
"""Aroon Indicator -- identifies trend direction and potential changes."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_aroon(symbol, length=length)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/cci", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_cci(
|
||||
symbol: str = Path(..., min_length=1, max_length=20),
|
||||
length: int = Query(default=14, ge=1, le=100),
|
||||
):
|
||||
"""Commodity Channel Index -- cyclical trend identification."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_cci(symbol, length=length)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/kc", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_kc(
|
||||
symbol: str = Path(..., min_length=1, max_length=20),
|
||||
length: int = Query(default=20, ge=1, le=100),
|
||||
):
|
||||
"""Keltner Channels -- ATR-based volatility bands."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_kc(symbol, length=length)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/fib", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_fib(
|
||||
symbol: str = Path(..., min_length=1, max_length=20),
|
||||
days: int = Query(default=120, ge=5, le=365),
|
||||
):
|
||||
"""Fibonacci Retracement -- key support/resistance levels."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_fib(symbol, days=days)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/ad", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_ad(symbol: str = Path(..., min_length=1, max_length=20)):
|
||||
"""Accumulation/Distribution Line -- volume-based trend indicator."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_ad(symbol)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
|
||||
@router.get("/stock/{symbol}/technical/cones", response_model=ApiResponse)
|
||||
@safe
|
||||
async def stock_cones(symbol: str = Path(..., min_length=1, max_length=20)):
|
||||
"""Volatility Cones -- realized vol quantiles for options analysis."""
|
||||
symbol = validate_symbol(symbol)
|
||||
data = await technical_service.get_cones(symbol)
|
||||
return ApiResponse(data=data)
|
||||
|
||||
Reference in New Issue
Block a user