Merge pull request '[REFACTOR] 한국투자증권(KIS) 데이터 수집 엔진 효율화 및 DB 인프라 최적화' (#2) from codex/topic-kis-collector into main
Quant Engine CI/CD Pipeline / validate-core (push) Has been cancelled
Quant Engine CI/CD Pipeline / validate-ui-and-storage (push) Has been cancelled
WBS-9.3 - NULL Policy CI Gate / NULL Policy Validation (push) Has been cancelled

Reviewed-on: http://178.104.200.7/kjh2064/QuantEngineByItz/pulls/2
This commit was merged in pull request #2.
This commit is contained in:
2026-06-25 15:26:52 +09:00
3 changed files with 20 additions and 14 deletions
+16 -10
View File
@@ -168,13 +168,16 @@ def _issue_or_reuse_token(creds: KisCredentials) -> str:
# 2. 토큰이 만료되었거나 없을 시 KIS API로 새로 발급 요청 # 2. 토큰이 만료되었거나 없을 시 KIS API로 새로 발급 요청
requests = _requests() requests = _requests()
resp = requests.post( try:
f"{creds.domain}/oauth2/tokenP", resp = requests.post(
json={"grant_type": "client_credentials", "appkey": creds.app_key, "appsecret": creds.app_secret}, f"{creds.domain}/oauth2/tokenP",
timeout=15, json={"grant_type": "client_credentials", "appkey": creds.app_key, "appsecret": creds.app_secret},
) timeout=15,
resp.raise_for_status() )
body = resp.json() resp.raise_for_status()
body = resp.json()
except Exception as exc:
raise RuntimeError("KIS token refresh failed; check credentials and API availability.") from exc
access_token = body["access_token"] access_token = body["access_token"]
expires_in_sec = int(body.get("expires_in", 86400)) expires_in_sec = int(body.get("expires_in", 86400))
expires_at = dt.datetime.now(dt.timezone.utc) + dt.timedelta(seconds=expires_in_sec) expires_at = dt.datetime.now(dt.timezone.utc) + dt.timedelta(seconds=expires_in_sec)
@@ -209,9 +212,12 @@ def _send_request(creds: KisCredentials, path: str, tr_id: str, params: dict[str
"custtype": "P", "custtype": "P",
} }
requests = _requests() requests = _requests()
resp = requests.get(f"{creds.domain}{path}", headers=headers, params=params, timeout=15) try:
resp.raise_for_status() resp = requests.get(f"{creds.domain}{path}", headers=headers, params=params, timeout=15)
return resp.json() resp.raise_for_status()
return resp.json()
except Exception as exc:
raise RuntimeError(f"KIS read-only request failed for {path} / {tr_id}.") from exc
# ── 조회(read-only) 함수 — 전부 GET, 전부 quotations/ranking 카테고리 (실측 확인) ────────── # ── 조회(read-only) 함수 — 전부 GET, 전부 quotations/ranking 카테고리 (실측 확인) ──────────
Binary file not shown.
+4 -4
View File
@@ -1,9 +1,9 @@
"""KIS-first data collector for the CI scheduler. """KIS-first data collector for the CI scheduler.
The collector uses the existing `GatherTradingData.json` snapshot as the seed The collector treats SQLite as the canonical persistence layer.
universe, then enriches Korean tickers with read-only KIS quotations and `GatherTradingData.json` is emitted only after the DB-backed collection run
orderbook data, while retaining Naver/Yahoo fallbacks when available. finishes, so the JSON acts as a derived reporting artifact rather than the
The canonical persistence target is SQLite. source of truth.
""" """
from __future__ import annotations from __future__ import annotations