Files
openbb-invest-api/routes_fixed_income.py
Yaojia Wang 87260f4b10 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.
2026-03-19 17:28:31 +01:00

94 lines
2.8 KiB
Python

"""Routes for fixed income data."""
from fastapi import APIRouter, Query
from models import ApiResponse
from route_utils import safe
import fixed_income_service
router = APIRouter(prefix="/api/v1/fixed-income")
@router.get("/treasury-rates", response_model=ApiResponse)
@safe
async def treasury_rates():
"""Full treasury yield curve rates (4W-30Y)."""
data = await fixed_income_service.get_treasury_rates()
return ApiResponse(data=data)
@router.get("/yield-curve", response_model=ApiResponse)
@safe
async def yield_curve(date: str = Query(default=None, max_length=10, pattern=r"^\d{4}-\d{2}-\d{2}$")):
"""Yield curve with maturity/rate pairs."""
data = await fixed_income_service.get_yield_curve(date=date)
return ApiResponse(data=data)
@router.get("/treasury-auctions", response_model=ApiResponse)
@safe
async def treasury_auctions(
security_type: str = Query(default=None, max_length=30, pattern=r"^[a-zA-Z_ -]+$"),
):
"""Treasury auction data: bid-to-cover ratios, yields."""
data = await fixed_income_service.get_treasury_auctions(security_type=security_type)
return ApiResponse(data=data)
@router.get("/tips-yields", response_model=ApiResponse)
@safe
async def tips_yields():
"""TIPS real yields by maturity."""
data = await fixed_income_service.get_tips_yields()
return ApiResponse(data=data)
@router.get("/effr", response_model=ApiResponse)
@safe
async def effr():
"""Effective Federal Funds Rate with percentiles and volume."""
data = await fixed_income_service.get_effr()
return ApiResponse(data=data)
@router.get("/sofr", response_model=ApiResponse)
@safe
async def sofr():
"""SOFR rate with 30/90/180-day moving averages."""
data = await fixed_income_service.get_sofr()
return ApiResponse(data=data)
@router.get("/hqm", response_model=ApiResponse)
@safe
async def hqm():
"""High Quality Market corporate bond yields (AAA/AA/A)."""
data = await fixed_income_service.get_hqm()
return ApiResponse(data=data)
@router.get("/commercial-paper", response_model=ApiResponse)
@safe
async def commercial_paper():
"""Commercial paper rates by maturity and type."""
data = await fixed_income_service.get_commercial_paper()
return ApiResponse(data=data)
@router.get("/spot-rates", response_model=ApiResponse)
@safe
async def spot_rates():
"""Corporate bond spot rates and par yields."""
data = await fixed_income_service.get_spot_rates()
return ApiResponse(data=data)
@router.get("/spreads", response_model=ApiResponse)
@safe
async def spreads(
series: str = Query(default="tcm", pattern="^(tcm|tcm_effr|treasury_effr)$"),
):
"""Treasury/corporate spreads (tcm, tcm_effr, treasury_effr)."""
data = await fixed_income_service.get_spreads(series=series)
return ApiResponse(data=data)