diff --git a/src/quant_engine/kis_api_client_v1.py b/src/quant_engine/kis_api_client_v1.py index 898b419..c8cb68e 100644 --- a/src/quant_engine/kis_api_client_v1.py +++ b/src/quant_engine/kis_api_client_v1.py @@ -168,13 +168,16 @@ def _issue_or_reuse_token(creds: KisCredentials) -> str: # 2. 토큰이 만료되었거나 없을 시 KIS API로 새로 발급 요청 requests = _requests() - resp = requests.post( - f"{creds.domain}/oauth2/tokenP", - json={"grant_type": "client_credentials", "appkey": creds.app_key, "appsecret": creds.app_secret}, - timeout=15, - ) - resp.raise_for_status() - body = resp.json() + try: + resp = requests.post( + f"{creds.domain}/oauth2/tokenP", + json={"grant_type": "client_credentials", "appkey": creds.app_key, "appsecret": creds.app_secret}, + timeout=15, + ) + 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"] expires_in_sec = int(body.get("expires_in", 86400)) 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", } requests = _requests() - resp = requests.get(f"{creds.domain}{path}", headers=headers, params=params, timeout=15) - resp.raise_for_status() - return resp.json() + try: + resp = requests.get(f"{creds.domain}{path}", headers=headers, params=params, timeout=15) + 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 카테고리 (실측 확인) ────────── diff --git a/src/quant_engine/kis_data_collection.db b/src/quant_engine/kis_data_collection.db index e141d3d..76ba7a0 100644 Binary files a/src/quant_engine/kis_data_collection.db and b/src/quant_engine/kis_data_collection.db differ diff --git a/src/quant_engine/kis_data_collection_v1.py b/src/quant_engine/kis_data_collection_v1.py index 1a45d5b..8347c2e 100644 --- a/src/quant_engine/kis_data_collection_v1.py +++ b/src/quant_engine/kis_data_collection_v1.py @@ -1,9 +1,9 @@ """KIS-first data collector for the CI scheduler. -The collector uses the existing `GatherTradingData.json` snapshot as the seed -universe, then enriches Korean tickers with read-only KIS quotations and -orderbook data, while retaining Naver/Yahoo fallbacks when available. -The canonical persistence target is SQLite. +The collector treats SQLite as the canonical persistence layer. +`GatherTradingData.json` is emitted only after the DB-backed collection run +finishes, so the JSON acts as a derived reporting artifact rather than the +source of truth. """ from __future__ import annotations