ls kiwoom 구독 히스토리 모두 적재

This commit is contained in:
Your Name
2026-07-30 20:23:37 +09:00
parent 67eab24603
commit 7050f788c5
18 changed files with 1379 additions and 120 deletions

View File

@@ -235,8 +235,7 @@ class KiwoomWebSocketPriceCache:
return True
def stop(self) -> None:
"""수신 스레드 종료 + 소켓 닫기."""
self._running = False
"""수신 스레드 종료 + 구독 REMOVE 후 소켓 닫기 (재시작 세션 꼬임 완화)."""
with self._reg_timer_lock:
if self._reg_timer:
try:
@@ -246,11 +245,35 @@ class KiwoomWebSocketPriceCache:
self._reg_timer = None
with self._sub_lock:
self._reg_batch_codes.clear()
codes = sorted(self._subscribed)
self._subscribed.clear()
# 서버에 등록된 종목 REMOVE — KIS stop(clear_subscriptions=True) 와 동일 목적
if codes and self._connected and self._authenticated and self._ws is not None:
try:
chunk = self._reg_chunk_size()
gap = self._reg_gap_sec()
n_ok = 0
for i in range(0, len(codes), chunk):
part = codes[i:i + chunk]
if self._send_remove(part):
n_ok += len(part)
if i + chunk < len(codes):
time.sleep(gap)
logger.info(
"✅ 키움 WS 종료 전 REMOVE %d/%d종목",
n_ok, len(codes),
)
except Exception as e:
logger.warning("키움 WS 종료 전 REMOVE 실패: %s", e)
self._running = False
self._connected = False
self._authenticated = False
try:
if self._ws is not None:
self._ws.close()
except Exception:
pass
logger.info("⏹ 키움 WS 종료")
def _max_subscriptions(self) -> int:
"""그룹당 최대 구독 수 — DB ``KIWOOM_WS_MAX_SUBSCRIPTIONS`` (기본 100)."""