docs/style(bat-052): QC 재검 비차단 minor 정리

- docs/operations.md: report 섹션을 WAC 실현PnL 정의로 갱신 (portfolio-hub WAC
  기반, 매수 fee cost basis 편입, 멀티데이 정확; 미가용 시 실현섹션 에러·타섹션 정상;
  당일 net 함수는 회귀 비교용 보존 명시)
- docs/runtime-flows.md: 운영 조회 리포트 흐름에 BAT-052 WAC 경로(get_realized_pnl
  N콜) + degrade(폴백 없음) 단계 추가
- docs/batches/bat-052_*/: CHG-20260626-02 기준으로 buy_fee_only_assets·
  buy_fee_by_asset 잔존 참조 제거 및 최종 구현 일치 갱신 (planning/design/
  implementation/verification)
- tests/application/test_operator_report.py:82: 섹션 헤더 주석에서
  buy_fee_by_asset 단어 제거 및 CHG-20260626-02 근거 추가 (주석만)
- trex_core/runtime/cli.py: __import__("datetime").timezone/timedelta inline
  패턴을 정식 from datetime import timezone, timedelta로 교체 (동작 동일)

pytest: 717 passed, 47 skipped (로직 변경 없음, 회귀 0)
This commit is contained in:
2026-06-26 20:35:17 +09:00
parent d3e4af59cf
commit a96fd54799
8 changed files with 31 additions and 26 deletions
+6 -4
View File
@@ -304,13 +304,15 @@ timeout 미지정·취소 실패로 잔여 고착된 pending 슬롯을 처분:
- **거부 ERROR 가시성(REQ-087)**: dispatch/poll 거부 롤백 시 `event=order_reject`를 **ERROR 레벨**로 — 조용한 롤백 제거(issue #28 이 수 시간 묻혔던 원인). 정상 체결은 INFO. 알림 전송 채널은 Deferred(OQ-3).
- **청산 reason+actor(REQ-086)**: `safety-sell fired: ... reason=<r> actor=trex-safety-sell` 로 조건축(reason)과 주체축(actor)을 함께 노출. `stop_loss`/`take_profit`/`forced_close_at` 는 watchdog expired 에서만 발화하므로 actor 동반으로 "안전망 자율청산 vs 전략 손절"을 구분(신규 reason 값·필드 없음). `slot_transition_log` 는 이미 actor 기록.
## Flow: `운영 조회 리포트 (trex-core report)` (BAT-046 / dcy-029, REQ-088)
## Flow: `운영 조회 리포트 (trex-core report)` (BAT-046 / dcy-029, REQ-088; BAT-052 / dcy-035, REQ-110/111)
운영자 `trex-core report [--json]` — **direct-DB 시점 집계**(신규 RPC 없음, OQ-1):
운영자 `trex-core report [--json]` — **direct-DB + portfolio-hub WAC 경로**(RPC 없음):
1. `daily_slot` 에서 보유(status=holding: symbol/qty/avg_price) + 대기(pending_*) 조회.
2. `ledger_outbox` 에서 오늘(trading_date KST 경계 → UTC 범위) 체결 조회.
3. `application/operator_report.py` 순수 집계: 실현 PnL = Σ매도(qty·price − fee − tax) − Σ매수(qty·price + fee) (net 매매 현금흐름, 수수료·세금 반영 BAT-038 정책, 자산별 분해). 일중 진입·청산 전략에서 net ≈ 실현손익(미청산 평가손익 제외).
4. text 표 또는 `--json` 출력. 일일 리포트 자동화 기반.
3. `application/operator_report.py` 순수 집계(`build_report`): 기존 당일 net(Σ매도−Σ매수) 계산 (회귀 보존, NFR-2).
4. **WAC 경로(REQ-110)**: `TREX_PORTFOLIO_HUB_BASE_URL` 설정 시 portfolio-hub `GET /v1/portfolios/{id}/pnl/realized` 를 portfolio_id 별 N회 호출(`get_realized_pnl(pid, from_dt, to_dt)`, from_dt/to_dt = 오늘 KST date). 응답의 `total_realized_pnl` / 자산별 `realized_pnl` 을 합산해 `apply_wac_to_report` 로 report 에 반영. 매수 fee 가 cost basis 에 편입된 WAC 기준이므로 멀티데이 정확.
5. **degrade(REQ-111)**: portfolio-hub 미설정 또는 `PortfolioHubUnavailableError` → `wac_unavailable=True` + `wac_unavailable_reason` 기록. 폴백 없음(당일 net 을 WAC 위치에 대체하지 않음). 보유/대기/체결 건수 섹션은 정상 출력.
6. text 표 또는 `--json` 출력. WAC 섹션 미가용 시 에러 메시지만 표시, 나머지 섹션 정상.
## Shared Components