diff --git a/app/execution/kis_client.py b/app/execution/kis_client.py index d4d52c4..b57daba 100644 --- a/app/execution/kis_client.py +++ b/app/execution/kis_client.py @@ -123,7 +123,19 @@ class KISClient: data = await resp.json() if "access_token" not in data: - raise RuntimeError(f"토큰 발급 실패: {data}") + # EGW00133: 분당 1회 제한 — 캐시 토큰이 아직 유효하면 그대로 사용 + if data.get("error_code") == "EGW00133" and self._access_token: + logger.warning("KIS 토큰 발급 속도 제한(EGW00133) — 기존 캐시 토큰 유지") + return self._access_token + # 캐시 없으면 60초 대기 후 1회 재시도 + if data.get("error_code") == "EGW00133": + logger.warning("KIS 토큰 발급 속도 제한(EGW00133) — 60초 후 재시도") + await asyncio.sleep(60) + async with aiohttp.ClientSession() as session: + async with session.post(url, json=body) as resp: + data = await resp.json() + if "access_token" not in data: + raise RuntimeError(f"토큰 발급 실패: {data}") self._access_token = data["access_token"] # 유효기간 24시간