Files
trex-core/docs/srs/Integration/req-013_order-execution-loop.md
T
genichinandClaude Opus 4.8 d60d720bc7 Add dcy-003 (confirmed) + REQ-011~015: broker execution + KIS + outbox
dcy-003 confirmed (all OQ answered, operator-confirmed scope/risk):
- OQ-1: paper/stub + real KIS Open API adapter (validated on KIS paper
  server; live account go-live config-gated, deferred).
- OQ-2: unified async fill (submit -> poll); paper is a deterministic
  async double (no synchronous shortcut) for faithful path coverage.
- OQ-3: option A — pending slot is the execution queue, broker_order_id
  is the idempotency guard; no separate outbox table (option B as a
  growth hook; intent_log stays dedup-only).
- OQ-4: dedicated background execution loop (claim -> submit -> poll ->
  reconcile); intent API only transitions to pending.

Decompose into REQ-011~015 (all Proposed): BrokerPort + paper double,
KIS adapter, execution loop, durability+reconciliation (Exception),
baseline alignment. NFR-1/2/3 absorbed. Update SRS index + dcy-003
created-REQ refs. Safety floor, KIS live account, strategy daemons, and
auth remain deferred to follow-up Discoveries.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 16:40:23 +09:00

3.2 KiB

req-013: 주문 집행 루프 (claim·송신·체결·롤백)

  • Status: Proposed
  • 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 + 멱등 + 롤백 테스트로 검증.