Files
trex-core/docs/batches/bat-017_20260608_external-cancel-detection-stale-watchdog/index.md
T
genichinandClaude Opus 4.8 4746f74aae fix(broker): dcy-013 KIS 외부 취소 감지 + 부분 체결 회계 + stale 워치독 (BAT-017)
KIS 계좌에서 직접 매도 주문을 취소하면 poll_fill 이 cncl_yn 을 파싱하지 않아
슬롯이 pending_sell 에 영구히 갇히고 죽은 주문을 무한 폴링하던 버그(issue #9)
정정.

거버넌스: 전부 change-req (신규 REQ 없음, dcy-013 OQ-3).
- REQ-012: KIS poll_fill cncl_yn 파싱 → 외부 취소 감지. FillStatus.cancelled
  /is_partial_cancel 추가. 체결 0 취소→cancelled, 부분 체결 후 취소→partial+cancelled
- REQ-013: 집행 _on_partial_cancel — 체결분 원장 1회 + qty 차감(매도 잔여/매수 체결분)
  + holding 복귀 (OQ-1 A안). 전량 취소는 기존 롤백 경로 재사용
- REQ-018: 부분 체결분 원장 1회 기록 (_record_ledger 재사용)
- REQ-031: 잔여 포지션 정합 연계 (slot.qty ↔ 실 잔고, 과매도 방지)
- REQ-014: pending stale 워치독 Alert-only (TREX_PENDING_STALE_THRESHOLD,
  WARN+카운터, 상태 미변경) — 취소 감지 누락 backstop
- REQ-015: interface-contract/runtime-flows 정합

전량 취소는 holding 자동 복구(limit_price clear→재매도 시장가, dcy-012 연계).
KIS cncl_yn 실 규약은 운영 검증(미지 값 보수 처리 + 워치독 backstop).

검증: 단위 294 passed/32 skipped, 인프라 게이트(PG+RabbitMQ) 326 passed, ruff clean.
신규 test_kis_cancel(httpx stub) + test_execution_cancel(programmable broker).
BAT-017 release-candidate.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-08 14:11:49 +09:00

2.9 KiB

BAT-017: KIS 외부 취소 감지 + 부분 체결 회계 + pending stale 워치독 (issue #9)

  • Status: release-candidate
  • Profile: standard
  • Source Discovery: dcy-013
  • Included REQ: REQ-012 (CHG-20260608-01), REQ-013 (CHG-20260608-02), REQ-018 (CHG-20260608-02), REQ-031 (CHG-20260608-01), REQ-014 (CHG-20260608-01), REQ-015 (CHG-20260608-02)

Summary

  • dcy-013(KIS 외부 주문 취소 시 슬롯이 pending_sell 에 영구 갇힘 — cncl_yn 미파싱, issue #9)을 단일 standard batch 로 delivery 한다. 거버넌스는 dcy-013 OQ-3 결정대로 전부 change-req, 신규 REQ 없음(워치독 임계 env 는 REQ-014 에 흡수).
  • 핵심: KIS poll_fill 이 inquire-daily-ccld 의 cncl_yn="Y" 를 파싱해 외부 취소를 감지한다. 체결 0 취소 → cancelled(기존 롤백 경로로 holding 자동 복구), 부분 체결 후 취소 → is_partial_cancel(체결분 원장 1회 + qty 차감 + 잔여 holding 복귀, OQ-1 A안). 보강책으로 pending 주문 stale 워치독(OQ-2 Alert-only: WARN+카운터, 상태 미변경).

Scope

  • In Scope:
    • KIS poll_fill 의 cncl_yn 파싱 + cancelled/partial-cancel 매핑, FillStatus.cancelled/is_partial_cancel (REQ-012)
    • 집행 루프 부분 체결 회계 _on_partial_cancel(체결분 원장 + qty 차감 + holding 복귀), 전량 취소 롤백 재사용 (REQ-013)
    • 부분 체결분 원장 1회 기록(_record_ledger 재사용) (REQ-018)
    • 잔여 포지션 정합 연계(슬롯 qty ↔ 실 잔고, 과매도 방지) (REQ-031)
    • pending stale 워치독 Alert-only + TREX_PENDING_STALE_THRESHOLD env (REQ-014)
    • baseline 문서(interface-contract/runtime-flows) 정합 (REQ-015)
  • Out of Scope:
    • buy 경로·paper 브로커 동작 변경(paper 는 이미 취소 정상 처리)
    • 매도 가격 정책(dcy-012/BAT-016 에서 처리 — 본 주기는 취소 감지만)
    • 워치독 auto-remediation(타임아웃 시 자동 롤백/취소) — 정상 slow fill·지정가 대기 상호작용·KIS 취소 능력 필요로 후속 분리
    • 과거 갇힘 슬롯의 일괄 보정(운영 절차)

Documents

Notes

  • Source discovery 단일(dcy-013). OQ-1(A안 정확 회계)·OQ-2(워치독 Alert-only)·OQ-3(전부 change-req) Answered.
  • 자동 회복 성립 근거: FillStatus.is_terminal_reject 가 이미 cancelled 를 포함하고 _rollback 이 pending_sell→holding 을 수행(A-2) → KIS 어댑터가 취소만 정확히 반환하면 application 경로 재사용으로 복구.
  • dcy-012(BAT-016) 가정 충족: holding 진입 시 limit_price clear → 재매도 시장가(A-1).
  • R-1(KIS 취소 필드 규약): cncl_yn 가정. 실 응답 확인은 운영/검증 단계 — 미지 값 보수 처리 + stale 워치독(FR-3) backstop.