Deliver BAT-004: broker execution + KIS adapter + durable handoff
Implement REQ-011~015 (dcy-003): the order-execution layer on top of the BAT-002 slot-core daemon, connecting intents to real orders. - application: BrokerPort (submit/poll_fill/cancel) + ExecutionService (claim -> submit -> poll -> transition -> rollback -> reconcile) - adapters/broker: PaperBroker (deterministic async double) and KISBroker (KIS Open API: token, order-cash, inquire-daily-ccld, cancel; VTS sandbox tr_ids; live account gated behind allow_live) - persistence: option-A execution queue (find_pending_for_dispatch FOR UPDATE SKIP LOCKED, mark_dispatched idempotency guard, clear_dispatch) - runtime: background execution loop in the daemon lifespan + startup reconcile; config selects paper|kis Verification (real KIS VTS 모의투자 + PostgreSQL): 92 passed, ruff clean, domain import sweep shows zero broker/web/db deps, buy->holding / sell->closed / reject->idle, idempotent dispatch (exactly one order), reconcile after crash creates no duplicate order, KIS sandbox token+submit round-trip, and a daemon E2E through the background loop. Align the four baseline docs. BAT-004 -> release-candidate; REQ-011~015 -> Implemented. KIS live-account go-live, partial-fill accrual, option-B outbox, connection pooling, and the safety floor remain deferred to follow-up Discoveries. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -62,22 +62,25 @@
|
||||
│ ├── domain/slot/ # slot 순수 도메인 (BAT-001, 무의존)
|
||||
│ │ ├── __init__.py · state.py · models.py(+EXPECTED_SLOT_FIELDS) · errors.py
|
||||
│ │ ├── repository.py(Protocol) · service.py · in_memory_repository.py
|
||||
│ ├── application/ # 유스케이스 (BAT-002)
|
||||
│ ├── application/ # 유스케이스 (BAT-002, BAT-004)
|
||||
│ │ ├── ports.py # IntentStore Protocol
|
||||
│ │ └── intents.py # IntentService / BuyIntent / SellIntent / IntentDecision
|
||||
│ ├── adapters/ # 인프라 어댑터 (BAT-002)
|
||||
│ │ ├── intents.py # IntentService / BuyIntent / SellIntent / IntentDecision
|
||||
│ │ ├── broker_port.py # BrokerPort + OrderRequest/OrderAck/FillStatus (BAT-004)
|
||||
│ │ └── execution.py # ExecutionService (claim·dispatch·poll·transition·reconcile)
|
||||
│ ├── adapters/ # 인프라 어댑터 (BAT-002, BAT-004)
|
||||
│ │ ├── api/ # FastAPI: app.py(create_app /v1) · schemas.py
|
||||
│ │ ├── broker/ # paper.py(결정적 async 더블) · kis.py(KIS Open API) (BAT-004)
|
||||
│ │ └── persistence/ # postgresql.py · in_memory_intent_store.py · migrate.py · sql/
|
||||
│ └── runtime/ # 데몬 (BAT-002)
|
||||
│ ├── config.py # DaemonConfig(env)
|
||||
│ └── daemon.py # build_app + lifespan(migrate/preallocate) + main(uvicorn)
|
||||
│ └── runtime/ # 데몬 (BAT-002, BAT-004)
|
||||
│ ├── config.py # DaemonConfig + KISConfig(env, broker 선택/게이팅)
|
||||
│ └── daemon.py # build_app + lifespan(migrate/preallocate/reconcile/execution 루프)
|
||||
└── tests/
|
||||
├── domain/slot/ # test_state / test_service / test_contract
|
||||
├── application/ # test_intent_concurrency (단일 writer)
|
||||
└── adapters/{api,persistence}/ # API(in-memory) · PG repo/migration/drift
|
||||
├── application/ # test_intent_concurrency · test_execution (집행 lifecycle)
|
||||
└── adapters/{api,broker,persistence}/ # API · paper/KIS · PG repo/migration/drift
|
||||
```
|
||||
|
||||
> 참고: domain(BAT-001)은 무의존 코어. application/adapters/runtime 은 BAT-002(dcy-002 FR-1~FR-6)에서 추가. 웹/DB 의존(fastapi/uvicorn/psycopg)은 adapters/runtime 에만 격리(NFR-1).
|
||||
> 참고: domain(BAT-001)은 무의존 코어. application/adapters/runtime 은 BAT-002 에서 추가, BAT-004 에서 broker/execution 레이어 확장. 웹/DB/브로커 의존(fastapi/uvicorn/psycopg/httpx)은 adapters/runtime 에만 격리(NFR). 브로커 주문은 BrokerPort 단일 세션(불변식 B), 슬롯 쓰기는 SlotService 단일 writer(불변식 A).
|
||||
|
||||
## Package / Module Responsibilities
|
||||
|
||||
@@ -121,3 +124,4 @@
|
||||
- 2026-06-03 :: dcy-001 OQ-1 결정 반영 — planned 네임스페이스를 `app/` → `trex_core/` 로 정정(배포명 `trex-core`).
|
||||
- 2026-06-03 :: BAT-001 이식 완료 반영 — `trex_core/`·`tests/`·`pyproject.toml` planned→실제 정합(REQ-004).
|
||||
- 2026-06-03 :: BAT-002 — application/adapters/runtime 레이어(데몬+HTTP API+PostgreSQL) 추가, Primary Runtime=daemon+library(REQ-005~009).
|
||||
- 2026-06-04 :: BAT-004 — 브로커 집행 레이어 반영(BrokerPort/paper·KIS 어댑터, execution 루프, broker_order_id 실행큐·멱등, reconciliation) (REQ-011~015).
|
||||
|
||||
Reference in New Issue
Block a user