KIS api 너무 잦은 호출로 인한 허용 횟수 제한으로 인터벌 늘림
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import time
|
||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from modules.services.kis import KISClient
|
from modules.services.kis import KISClient
|
||||||
@@ -31,6 +32,8 @@ class MacroAnalyzer:
|
|||||||
|
|
||||||
for name, code in indicators.items():
|
for name, code in indicators.items():
|
||||||
data = kis_client.get_current_index(code)
|
data = kis_client.get_current_index(code)
|
||||||
|
time.sleep(0.6) # Rate Limit 방지 (초당 2회 제한)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
price = data['price']
|
price = data['price']
|
||||||
change = data['change']
|
change = data['change']
|
||||||
@@ -46,6 +49,7 @@ class MacroAnalyzer:
|
|||||||
results[name] = {"price": 0, "change": 0}
|
results[name] = {"price": 0, "change": 0}
|
||||||
|
|
||||||
# [신규] 시장 스트레스 지수(MSI) 추가
|
# [신규] 시장 스트레스 지수(MSI) 추가
|
||||||
|
time.sleep(0.6) # MSI 계산 전 추가 대기
|
||||||
kospi_stress = MacroAnalyzer.calculate_stress_index(kis_client, "0001")
|
kospi_stress = MacroAnalyzer.calculate_stress_index(kis_client, "0001")
|
||||||
results['MSI'] = kospi_stress
|
results['MSI'] = kospi_stress
|
||||||
print(f" - Market Stress Index: {kospi_stress}")
|
print(f" - Market Stress Index: {kospi_stress}")
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ class KISClient:
|
|||||||
self.last_req_time = 0
|
self.last_req_time = 0
|
||||||
|
|
||||||
def _throttle(self):
|
def _throttle(self):
|
||||||
"""API 요청 속도 제한 (초당 5회 이하로 제한)"""
|
"""API 요청 속도 제한 (초당 2회 이하로 제한)"""
|
||||||
# 모의투자는 Rate Limit이 더 엄격할 수 있음
|
# 모의투자는 Rate Limit이 매우 엄격함 (초당 2~3회 권장)
|
||||||
min_interval = 0.2 # 0.2초 대기
|
min_interval = 0.5 # 0.5초 대기 (초당 2회)
|
||||||
now = time.time()
|
now = time.time()
|
||||||
elapsed = now - self.last_req_time
|
elapsed = now - self.last_req_time
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user