- GET /api/v1/market/indices — 네이버 JSON API(비-KIS), 45초 캐시 - 부분 실패 시 직전값 병합, 전부 실패 시 12초 쿨다운 + 직전 캐시 반환 - 방향 code 해석 불가 시 원 부호 폴백, NaN/inf 거부 - MarketIndexBar: 60초 갱신, 상승 빨강/하락 파랑, 장 마감 배지 - 테스트 12건 (전체 877 passed) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
23 lines
614 B
Python
23 lines
614 B
Python
"""전체시장 지수 API (읽기 전용)
|
|
|
|
- GET /api/market/indices : KOSPI/KOSDAQ/KOSPI200 + S&P500/NASDAQ
|
|
"""
|
|
from datetime import datetime
|
|
|
|
from fastapi import APIRouter
|
|
from fastapi.responses import Response
|
|
|
|
from app.core.json_helpers import _dumps
|
|
from app.services.market_indices import get_market_indices_cached
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/indices")
|
|
async def get_indices():
|
|
items = await get_market_indices_cached()
|
|
return Response(
|
|
content=_dumps({"indices": items, "count": len(items), "fetched_at": datetime.now().isoformat()}),
|
|
media_type="application/json",
|
|
)
|