feat(home+search): KOSPI/KOSDAQ 인덱스 카드 + 검색결과 미니 sparkline

- Sparkline 컴포넌트를 PriceHero 내부에서 web/components/Sparkline.tsx 로 분리·재사용
- /api/markets/indices: macro_daily 의 kospi/kosdaq N일 시계열 + 최신값/전일대비
- 홈 IndicesPanel: 두 인덱스 카드(현재값/등락/우측 sparkline)
- /api/symbols/search?with_sparkline=true: 결과 한 번에 최근 30 종가 batch 조회
- SearchBox 결과 행에 mini sparkline + 현재가/등락률 인라인 표시

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
claude-owner
2026-05-28 14:46:13 +09:00
parent 66a28cc7ca
commit ae4f07d675
8 changed files with 330 additions and 71 deletions

View File

@@ -118,6 +118,60 @@ def movers(
}
@router.get("/indices")
def indices(days: int = Query(default=60, ge=2, le=400)) -> dict:
"""KOSPI / KOSDAQ 지수 N일 종가 시계열.
macro_daily 에 yfinance 가 채우는 'kospi','kosdaq' key 를 그대로 읽음.
채워져 있지 않으면 series 가 빈 배열로 반환되어 프런트가 '데이터 준비 중' 안내.
"""
sql = text(
"""
SELECT date, key, value
FROM macro_daily
WHERE key IN ('kospi','kosdaq')
AND date >= (CURRENT_DATE - (:d || ' day')::interval)
ORDER BY date ASC
"""
)
eng = get_engine()
with eng.connect() as conn:
rows = conn.execute(sql, {"d": days}).all()
series: dict[str, list[dict]] = {"kospi": [], "kosdaq": []}
for r in rows:
d, k, v = r[0], r[1], r[2]
if v is None:
continue
series.setdefault(k, []).append({"date": str(d), "value": float(v)})
def _summary(pts: list[dict]) -> dict:
if not pts:
return {"latest": None, "prev": None, "pct_change": None}
latest = pts[-1]["value"]
prev = pts[-2]["value"] if len(pts) >= 2 else None
pct = ((latest - prev) / prev * 100) if (prev and prev > 0) else None
return {"latest": latest, "prev": prev, "pct_change": pct}
return {
"days": days,
"indices": [
{
"key": "kospi",
"name": "KOSPI",
"points": series["kospi"],
**_summary(series["kospi"]),
},
{
"key": "kosdaq",
"name": "KOSDAQ",
"points": series["kosdaq"],
**_summary(series["kosdaq"]),
},
],
}
@router.get("/related/{code}")
def related(code: str, limit: int = Query(default=8, ge=1, le=30)) -> dict:
"""같은 market 에서 등락률 절대값 기준 가까운 종목 N 개.