auto: 일일 백업 2026-09-22 02:00

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
hyowons
2026-09-22 02:00:05 +09:00
parent 8e12b4027c
commit 408a3e0d4a
133 changed files with 1748 additions and 1597 deletions
@@ -81,6 +81,15 @@ def idempotency_hash(account: str, symbol: str, side: str, qty: int, price: int
return hashlib.sha256(key.encode('utf-8')).hexdigest()[:16]
# 멱등성 매칭 대상 — **이중 발주 위험이 실재하는 이벤트만** 본다.
# submitted : 키움이 접수했다 (확정)
# failed : 네트워크 에러 — 나갔는지 모른다 (가장 위험, 반드시 차단)
# rejected(브로커 거부·idem 중복)·dryrun 은 접수되지 않은 게 확정이라 재시도를 막지 않는다.
# ⚠️ 이게 없으면 키움이 거부한 직후 같은 주문을 다시 내는 게 90초간 IDEMPOTENCY_DUP 으로
# 막혀, 관리자님이 영문 모를 두 번째 실패를 본다 (2026-09-21 SOR 스톱 거부 때 실측).
IDEM_MATCH_EVENTS = ('submitted', 'failed')
def find_recent_idempotency(h: str, within_seconds: int = 90) -> Optional[dict]:
path = _ledger_path()
if not path.exists():
@@ -99,7 +108,8 @@ def find_recent_idempotency(h: str, within_seconds: int = 90) -> Optional[dict]:
continue
if ts < cutoff:
return None
if rec.get('payload', {}).get('idem_hash') == h:
if (rec.get('event') in IDEM_MATCH_EVENTS
and rec.get('payload', {}).get('idem_hash') == h):
return rec
return None