[2026-05-19] KIS 토큰 EGW00133 처리 개선 — 캐시 재사용 + 60초 재시도
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -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시간
|
||||
|
||||
Reference in New Issue
Block a user