[2026-05-18] KIS API rate limit 수정 — 모의투자 1건/초, 진입체크 불필요 호출 제거
This commit is contained in:
@@ -49,9 +49,10 @@ class KISClient:
|
||||
self._access_token : Optional[str] = None
|
||||
self._token_expires_at: Optional[datetime] = None
|
||||
|
||||
# rate limit: 초당 20건
|
||||
self._semaphore = asyncio.Semaphore(20)
|
||||
self._req_times : list = []
|
||||
# rate limit: 모의투자 1건/초, 실거래 5건/초
|
||||
self._rate_limit = 1 if self.is_mock else 5
|
||||
self._semaphore = asyncio.Semaphore(1)
|
||||
self._req_times : list = []
|
||||
|
||||
mode = "모의투자" if self.is_mock else "실거래"
|
||||
logger.info(f"KISClient 초기화 완료 [{mode}] 계좌: {self.account_no}")
|
||||
@@ -127,10 +128,9 @@ class KISClient:
|
||||
}
|
||||
|
||||
async with self._semaphore:
|
||||
# 초당 20건 rate limit
|
||||
now = time.monotonic()
|
||||
self._req_times = [t for t in self._req_times if now - t < 1.0]
|
||||
if len(self._req_times) >= 20:
|
||||
if len(self._req_times) >= self._rate_limit:
|
||||
wait = 1.0 - (now - self._req_times[0])
|
||||
if wait > 0:
|
||||
await asyncio.sleep(wait)
|
||||
|
||||
Reference in New Issue
Block a user