Files
trex-core/docs/batches/bat-038_20260612_sell-transaction-tax-fee/implementation.md
T
genichinandClaude Opus 4.8 1cf13b060f feat(broker): BAT-038 — 매도 증권거래세 누락 정정 + fee/tax 단일 정책 지점 (dcy-026/REQ-018, issue #24)
dcy-026 confirm-discovery + REQ-018 change-req(CHG-20260612-01)→구현→
confirm-req-implemented(CHG-20260612-02) 전체 delivery.

- broker_port.py: calculate_tax(side, amount) 신규 + fee/tax 율 env 상수화
  (TREX_KIS_FEE_BPS=1.5, TREX_KRX_TAX_SELL_BPS=20.0). 매도 0.2%/매수 0.
- paper.py / kis.py: tax=0.0 하드코딩 3곳 제거 → 정책 함수 호출.
  KIS daily-ccld 응답에 fee/tax 필드 부재 → 정책 폴백(향후 정본 우선 훅).
- runtime-flows.md: 체결→ledger fee/tax 산출 흐름 갱신.
- tests: fee/tax 정책 단위 + issue #24 4건 회귀(fee+tax=1,376.9원).
  429 passed (+6), ruff clean.

REQ-018 Approved→Implemented, BAT-038 release-candidate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-12 17:57:15 +09:00

2.8 KiB
Raw Blame History

BAT-038 Implementation

  • Status: completed
  • Batch: BAT-038

Plan Summary

  • broker_port.py 에 calculate_tax(side, amount) 신규 + fee/tax 율을 env 로딩 상수로 통일. paper/kis 의 3개 tax=0.0 사이트를 calculate_tax 호출로 교체. runtime-flows fee/tax 흐름 갱신. 회귀 테스트 추가.

Changed Files

  • trex_core/application/broker_port.py — import os; _FEE_BPS(TREX_KIS_FEE_BPS, 1.5)·_TAX_BPS_SELL(TREX_KRX_TAX_SELL_BPS, 20.0) env 상수; calculate_tax(side, amount) 신규; calculate_fee 단일 rate 정리; FillStatus.tax 주석 갱신
  • trex_core/adapters/broker/paper.py — calculate_tax import; line 90 tax=0.0 → tax=calculate_tax(o.side, amount)
  • trex_core/adapters/broker/kis.py — calculate_tax import; 전량(213)·부분(230) tax=0.0 → tax=calculate_tax(side, amount); KIS 응답 fee/tax 필드 부재 주석
  • docs/runtime-flows.md — 체결 → ledger outbox flow line 254 fee/tax 정책 + Change Log
  • tests/application/test_fee_tax_policy.py — 신규 (6 테스트)

Execution Log

  1. broker_port.py: os import 추가, _FEE_BPS/_TAX_BPS_SELL env 로딩 상수, calculate_tax 추가(매도 amount × _TAX_BPS_SELL / 10_000, 매수/비양수 0), FillStatus.tax 주석을 dcy-026 정책으로 갱신
  2. paper.py: calculate_tax import, fill 시 amount = o.filled * o.price 로 fee/tax 동시 계산
  3. kis.py: calculate_tax import, 전량·부분 체결 두 경로 모두 amount 기준 fee/tax 계산. daily-ccld 응답 fee/tax 필드 부재 → 정책 추정값 사용(주석)
  4. runtime-flows.md: line 254 tax=0 → calculate_tax 정책 계산 + env 변수 + paper·KIS 공유 설명, Change Log 항목 추가
  5. test_fee_tax_policy.py: policy 함수 단위(fee buy/sell 동일, tax sell-only, 비양수 0), issue #24 4건 회귀(1,376.9원), paper sell fill tax 정책 운반, paper buy fill tax=0

Validation

  • pytest tests/application/test_fee_tax_policy.py test_execution_ledger.py test_execution_cancel.py — 19 passed (신규 6 포함, 기존 회귀 없음)
  • pytest tests/ — 429 passed, 45 skipped (BAT-037 기준 423 → +6 신규, 회귀 0)
  • ruff check trex_core tests — All checks passed
  • 회귀 기준 확인: issue #24 4건 fee 합계 177.9 + tax 합계 1,199 = 1,376.9원 (테스트로 고정)
  • 기존 test_buy_fill...:61 t.tax == 0.0 은 매수 케이스로 정합 유지(AC-6). test_execution_cancel.py stub FillStatus(tax=0.0)는 execution 로직 테스트로 무영향.

Remaining Risks

  • 없음. R-1(세율 오류)은 1,376.9원 회귀로 고정, R-2(KIS 오파싱)는 설계상 제거(daily-ccld fee/tax 필드 부재 → 정책 폴백), R-3(전달 경로)은 점검 완료(불변).
  • 라이브 KIS 스모크는 운영 배포 단계(REL) 사항 — paper 정책과 동일 산식이므로 코드 경로 동일.