feat(phase-1a): external data fetchers + refresh pipeline + scheduler
10종목 시드 + pykrx OHLCV / 외인·기관 거래대금, KIS read-only EOD, OpenDART
공시, 네이버 금융 뉴스 스크레이퍼, 구글 뉴스 RSS, yfinance 거시(KOSPI/KOSDAQ/
USDKRW/US10Y) fetcher 를 추가하고 refresh_one / daily_batch / backfill /
APScheduler(16:00 KST) 파이프라인으로 묶음.
- backend/app/seed: 10종목 시드 (대형/고변동/테마/플랫폼/방어)
- backend/app/fetch: pykrx, kis, dart, news, macro, symbols_seed
- backend/app/pipelines: refresh_one, daily_batch, backfill(CLI), scheduler
- backend/app/api/refresh.py: POST /api/refresh/{code}?lookback_days=N
- backend/app/main.py: lifespan 으로 스케줄러 기동/종료, /health/keys 추가
- README: .env 복사 안내 보강
스모크 테스트 (실제 키 사용) 결과:
KIS token : ok (token 346자 발급)
KIS daily : 005930 11rows
DART list : 005930 30일 10건
Naver news : 005930 12건
Google RSS : "삼성전자" 92건
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
35
backend/app/api/refresh.py
Normal file
35
backend/app/api/refresh.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""검증용 수동 갱신 API.
|
||||
|
||||
POST /api/refresh/{code}
|
||||
body: 없음
|
||||
query: ?lookback_days=7 (기본)
|
||||
resp: refresh_one.RefreshReport.to_dict()
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Query
|
||||
from sqlalchemy import text
|
||||
|
||||
from app.db.connection import get_engine
|
||||
from app.pipelines.refresh_one import refresh_code
|
||||
|
||||
router = APIRouter(prefix="/api", tags=["refresh"])
|
||||
|
||||
|
||||
def _resolve_name(code: str) -> str | None:
|
||||
eng = get_engine()
|
||||
with eng.connect() as conn:
|
||||
row = conn.execute(text("SELECT name FROM symbols WHERE code = :code"), {"code": code}).first()
|
||||
return row[0] if row else None
|
||||
|
||||
|
||||
@router.post("/refresh/{code}")
|
||||
def refresh_endpoint(
|
||||
code: str,
|
||||
lookback_days: int = Query(default=7, ge=1, le=365),
|
||||
) -> dict:
|
||||
name = _resolve_name(code)
|
||||
if not name:
|
||||
raise HTTPException(status_code=404, detail=f"unknown code: {code} (symbols 테이블에 없음. 시드 필요)")
|
||||
report = refresh_code(code, name, lookback_days=lookback_days)
|
||||
return report.to_dict()
|
||||
Reference in New Issue
Block a user