# req-013: 주문 집행 루프 (claim·송신·체결·롤백) - Status: Implemented - Type: Integration - Priority: High - Owner: project maintainers ## Intent - 코어 데몬 내 백그라운드 execution 루프가 pending 슬롯을 집행해 브로커에 주문을 송신하고 체결을 슬롯 상태로 반영한다(불변식 A 단일 writer 유지). intent API 는 pending 전이까지만, 집행은 루프가 비동기 수행. ## Requirement - 데몬 프로세스 내 별도 execution 루프가 주기적으로: ① `pending_buy`/`pending_sell` 슬롯을 `FOR UPDATE SKIP LOCKED`(broker_order_id IS NULL)로 claim → `BrokerPort.submit_order` → `broker_order_id` 기록(옵션 A), ② broker_order_id 있는 pending 슬롯을 `poll_fill` 로 비동기 관측해 매수 체결 시 `pending_buy→holding`(avg_price/qty), 매도 체결 시 `pending_sell→closed`(recovery 재진입 +1), ③ 거부/취소 시 `pending_buy→idle` 롤백을 수행한다. 모든 슬롯 쓰기는 SlotService(advisory lock) 단일 경로. ## Acceptance Criteria 1. Given pending_buy 슬롯(paper), When 집행 루프 1회, Then 매수 주문 송신 + broker_order_id 기록, broker_order_id 채워진 슬롯은 재디스패치되지 않는다(멱등). (NFR-2 단일 writer) 2. Given 송신된 매수 주문이 체결(poll), When 루프, Then `pending_buy→holding`(avg_price/qty 반영). 3. Given 매수 주문 거부(poll), When 루프, Then `pending_buy→idle` 롤백. 4. Given pending_sell 슬롯, When 집행+체결, Then 매도 주문 송신 → `pending_sell→closed` + 재진입 +1. 5. Given 슬롯 쓰기 경로, When 점검, Then 집행 루프도 SlotService(advisory lock)로만 슬롯을 전이한다(브로커 직접 슬롯 쓰기 없음). ## Impacted Area - Docs: docs/runtime-flows.md(집행/체결 흐름) — REQ-015 - Modules: trex_core/application 또는 runtime(execution 루프), SlotService 재사용 - Tests: paper 더블로 매수/매도 lifecycle, 멱등 재디스패치, 거부 롤백, 체결→전이 ## Notes - OQ-3(옵션 A 실행큐)·OQ-4(별도 루프)·OQ-2(비동기 poll) 결정 반영. 폴링 주기/배치 크기는 config. - reconciliation·크래시 복구는 REQ-014. KIS 어댑터는 REQ-012, paper 는 REQ-011. - 출처: dcy-003 FR-2, FR-3, FR-4. NFR-2 흡수. ## Change Log ### CHG-20260604-01 - Date: 2026-06-04 - Author: Justin Ko #### Change Summary - dcy-003 FR-2·FR-3·FR-4 로부터 최초 생성(Proposed). NFR-2 흡수. #### Intent - 주문 집행 루프(매수/매도 claim·송신·체결·롤백) 요구사항을 backlog 로 정규화. #### Acceptance Criteria Delta - Added: - 매수 claim/멱등, 매수 체결→holding, 거부 롤백, 매도 체결→closed, 단일 writer 5개 기준 - Updated: - 없음 - Removed: - 없음 #### Impacted Area Delta - Docs: - docs/runtime-flows.md - Modules: - application/runtime(execution 루프) - Tests: - paper lifecycle/멱등/롤백/체결 테스트 #### Delivery Trace Delta - Batches: - none - Releases: - none #### Revalidation Impact - Reverification Needed: no - Existing Implementation Invalidated: no - Status Recommendation: keep-current - Follow-up Action: confirm-req 후 batch 편성 #### Validation Plan - paper 더블 매수/매도 lifecycle + 멱등 + 롤백 테스트로 검증. ### CHG-20260604-02 - Date: 2026-06-04 - Author: Justin Ko #### Change Summary - Status Proposed → Approved (confirm-req). #### Intent - 승인 게이트(필수 필드·구체 AC·blocker 없음) 충족, source dcy-003(confirmed, handoff 승인)와 모순 없음 확인. #### Acceptance Criteria Delta - Added: - 없음 - Updated: - 없음 - Removed: - 없음 #### Impacted Area Delta - Docs: - docs/srs/index.md (Register 상태 Approved) - Modules: - 없음 - Tests: - 없음 #### Delivery Trace Delta - Batches: - none (batch 편성 전) - Releases: - none #### Revalidation Impact - Reverification Needed: no - Existing Implementation Invalidated: no - Status Recommendation: keep-current - Follow-up Action: suggest-batch-reqs / draft-batch 로 delivery batch 편성 #### Validation Plan - 승인 후 batch planning 에서 본 REQ 의 Acceptance Criteria 를 검증 기준으로 사용. ### CHG-20260604-03 - Date: 2026-06-04 - Author: Justin Ko #### Change Summary - Status Approved → Implemented (confirm-req-implemented, 근거 batch BAT-004 release-candidate). #### Intent - BAT-004 verification.md 의 acceptance mapping + evidence(pytest 92 pass / 도메인 순수성 / 데몬 E2E / KIS VTS 모의투자 round-trip)로 AC 충족 → 구현 완료 동기화. #### Acceptance Criteria Delta - Added: - 없음 - Updated: - 없음 - Removed: - 없음 #### Impacted Area Delta - Docs: - docs/srs/index.md (Register Implemented) - Modules: - 없음 - Tests: - 없음 #### Delivery Trace Delta - Batches: - BAT-004 (release-candidate) - Releases: - none #### Revalidation Impact - Reverification Needed: no - Existing Implementation Invalidated: no - Status Recommendation: keep-current - Follow-up Action: draft-release 로 release 편성(BAT-001~004) #### Validation Plan - BAT-004 verification evidence 재참조로 충분.