데몬이 시스템 UTC 날짜로 슬롯을 1회만 preallocate 해 trading_date 가 KST 캘린더와
어긋나고 재시작 없이는 다음날 슬롯이 안 생기던 문제(issue #14) 정정.
거버넌스: 전부 change-req (신규 REQ 없음, dcy-014 OQ-3; 스케줄러는 REQ-030 패턴 준용).
- REQ-005: trading_date 를 설정 타임존(기본 Asia/Seoul) 기준 계산(timestamp 는 UTC
유지). DailyPreallocationScheduler 신규 — TZ 일자당 1회 멱등 fire, 재시작 없이
다음날 슬롯 자동 생성. setup() 배선 + trex-preallocation 스레드
- REQ-048: TOML trading_timezone/daily_preallocation_time 키 + from_config 전파
- REQ-009: runtime-flows/data-model 정합 + instance.example.toml
OQ-1 기본 00:00(TZ 자정, TOML 설정 가능) / OQ-2 매 캘린더일 생성(거래일 캘린더 후속).
멱등 preallocate 로 중복 tick·다중 인스턴스 중복 생성 0.
검증: 단위 302 passed/32 skipped, 인프라 게이트(PG+RabbitMQ) 334 passed, ruff clean.
신규 test_preallocation_scheduler(고정 clock) + test_instance_config 확장.
BAT-018 release-candidate.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
배포 차단 아님 전제로 실 KIS 쓰기 경로 4가지 미검증을 Verification Checklist에 명시:
LIVE 체결→ledger 미실증, kill_switch LIVE 미실행, 실 2-인스턴스 동시기동 미검증,
거래일 성공 LIVE 주문 0건 + 운영 DB 최초 적용. + 배포 후 차기 거래일 실증 권고.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
## REQ-038 CHG-04/05: KIS 시세 tr_id 정정 (FHKST01010100)
- kis.py _tr_price(): TTTC8397R/VTTC8397R → FHKST01010100 (실전/모의 공용)
배포 전 실 KIS LIVE 진단에서 구 tr_id가 rt_cd=1 "없는 서비스 코드"로 거부됨을
확인 — stop-loss/take-profit이 LIVE에서 조용히 미발동하는 결함이었음.
FHKST01010100으로 정정 후 get_current_price('005930')=329000(rt_cd=0) 확인.
- test_kis_price.py: AC-7 테스트 정정 (FHKST01010100 공용 검증)
- REQ-038: CHG-04/05 Change Log 추가, Requirement/AC-7/Notes 정정
- BAT-011 implementation.md: LIVE 검증 및 tr_id 정정 이력 추가
- BAT-011 verification.md: AC-7 evidence를 CHG-04 정정 버전으로 갱신
- docs/srs/index.md: CHG-04/05 Change Log 항목 추가
## REL-003: core 자율 안전 매도 release 문서 생성
- docs/releases/rel-003_20260607_core-autonomous-safety-sell.md 신규 생성
(BAT-010 + BAT-011, app-service profile, Status: confirmed)
- docs/releases/index.md: REL-003 행 추가
## dcy-008: 비상 정지/강제 청산(kill-switch) Discovery 초안
- docs/discovery/dcy-008_20260607_emergency-stop-kill-switch.md 신규 생성
GitHub #3 기반; SlotService.sell() 재사용, 당일 전략 제외 day-scoped
FR 6개, NFR 3개, OQ 4개 (트리거 표면/영속 방식/수동 해제 결정 필요)
- docs/discovery/index.md: dcy-008 행 추가
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Record deployment evidence for REL-002 (tooling): bat-009 fast-forward
merged to main and pushed (ca75700..7b6ed55). No migration/restart;
broker=kis unaffected. Status confirmed -> released.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
REL-002 bundles BAT-009 (paper broker env tuning, REQ-010 AC-5) as a
tooling-profile release. Rollout/rollback/verification ready; status
confirmed. No DB migration or daemon restart; broker=kis runtime
unaffected (paper config only).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Bundle BAT-001~008 into REL-001 (app-service profile) and promote to
confirmed. Register index row added.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
REQ-017 CHG-20260606-01. Live portfolio-hub returned 404 for the
trex-orbit-assumed POST /v1/assets/{asset_id}/ledger/trades. Correct to
POST /v1/portfolios/{portfolio_id}/ledger/trades with body keys
quantity/fee_amount/tax_amount (was qty/fee/tax), success 201. Reverified
with live e2e (201 Created, outbox COMPLETED) + durability drain of the
prior 404'd item. Resolves the REL-001 ledger-write release blocker.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Align REQ-027 and BAT-008 verification/design with the live portfolio-hub
API discovered during release prep: whoami via /v1/user_info, {portfolios}
envelope, client-side managed_by_daemon_id filter, http:// scheme default,
and strategy fields deferred (None/{}). Records the re-verification evidence
(new contract tests + live e2e) so BAT-008 can bundle into the first release
with non-stale verification. REQ-027 stays Implemented.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Record that the first strategy (orb-v1) queries view=buyable without a
strategy_key, so missing PortfolioItem strategy fields are harmless for the
single-strategy stage. Documentation-only; REQ-029 stays Implemented.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- new-discovery dcy-005: read-direction follow-up of dcy-004 (deferred
get_assets/get_portfolios). trex-core exposes portfolio-hub asset snapshot
as a read API, returning buy candidates with slot-occupied symbols filtered
out (slot overlay) and an empty list when no slots remain.
- 6 open questions pinned: snapshot shape, freshness/cache, core-proxy policy,
in-flight overlay (ledger outbox eventual consistency), availability degrade,
empty-list semantics.
- Link dcy-004 후속 Discovery 참조 → dcy-005; add dcy-005 to discovery index.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Record fills to the portfolio-hub ledger (orbit post_ledger_trade pattern)
so external accounting/positions reflect trades. The slot already carries
portfolio_id but nothing consumes it; this closes a deferral not previously
made explicit in dcy-003. Scope: LedgerPort + portfolio-hub adapter + stub,
record on buy/sell fill, execution_id idempotency, failure retry/hold;
out of scope: non-trade transactions, asset sync, reconciliation. OQ-1
(asset_id source), OQ-2 (durability), OQ-3 (exec data source) left for
confirm-discovery; handoff held.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Port the trex-orbit Redis token-cache pattern so the KIS access token
survives daemon restarts and is shared across processes, avoiding KIS
token-issuance rate limits. KISBroker._ensure_token now resolves L1
in-memory -> L2 cache -> issue, storing issued tokens back to the cache.
- adapters/broker/token_cache.py: TokenCache protocol + RedisTokenCache
(key trex:broker:kis:{account_ref}:token, token+expiry+app_key suffix
JSON, ex=ttl, best-effort with graceful fallback) + InMemoryTokenCache.
- kis.py: optional token_cache injection.
- runtime config/daemon: TREX_KIS_REDIS_URL wires a RedisTokenCache.
- pyproject: redis>=5.
Verification: 96 passed, ruff clean — cache hit avoids issuance, cache is
shared across instances (restart/multi-process survival), backend errors
fall back to issuance (no regression), and app_key-suffix mismatch
invalidates a stale cache. Tested deterministically with an in-memory
double (no Redis server required). Processed via the minor-change fast
path: REQ-016 -> Implemented, BAT-005 (batch-lite) -> release-candidate.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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>
DaemonConfig.from_env() now best-effort loads a .env file (find_dotenv
usecwd, load_dotenv override=False) so operators can manage daemon env
vars via .env, with real OS env taking precedence. Add python-dotenv
dependency, gitignore .env, ship .env.example, and add config tests
(load / OS-env precedence / absence regression / missing-DSN guard).
Verification: 78 passed, ruff clean, .env ignored + .env.example tracked,
and a .env-only DaemonConfig smoke. Processed via the minor-change fast
path: REQ-010 (Configuration) -> Implemented, BAT-003 (batch-lite,
no design) -> release-candidate.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Implement REQ-005~009 (dcy-002 slice 1) as an onion stack on top of the
BAT-001 pure domain:
- application: IntentService (admission + single-writer transition +
intent_id idempotency via durable intent_log)
- adapters/persistence: PostgreSQLSlotRepository + PostgreSQLIntentStore +
trex-core-owned migrations (daily_slot per Appendix A, daily_symbol_entries,
slot_transition_log, intent_log) + in-memory intent store
- adapters/api: FastAPI /v1 (healthz, intents/buy|sell|{id}, slots, capacity)
- runtime: trex-core-daemon entrypoint with lifespan migrate+preallocate
Verification (against local PostgreSQL 18): 74 passed, ruff clean, domain
import sweep shows zero web/db deps (NFR-1), 20-thread concurrency admits
exactly the idle count (NFR-2), idempotent resubmit causes no double
transition (NFR-3), EXPECTED_SLOT_FIELDS<->information_schema drift test
(realizes dcy-001 OQ-2's deferred DB-side check), and a daemon E2E smoke.
Align all four baseline docs to the new daemon/API/persistence layers.
BAT-002 -> release-candidate; REQ-005~009 -> Implemented. Full async outbox,
broker execution, safety floor, and strategy daemons remain deferred to a
follow-up Discovery.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Second iteration scope: promote the slot pure-domain core to a long-lived
daemon exposing a versioned HTTP API for buy/sell strategy daemons, backed
by durable single-writer PostgreSQL persistence.
All open questions resolved and operator-confirmed:
- OQ-1 durability: synchronous commit + intent_id idempotency + durable
intent_log seam; full async outbox deferred to the broker-execution
Discovery.
- OQ-2 framework: FastAPI + uvicorn.
- OQ-3 endpoints: /v1 set (healthz, intents/buy, intents/sell,
intents/{id}, slots, capacity); cancel/preallocate excluded.
- OQ-4 schema: trex-core-owned migrations keyed to dcy-001 Appendix A
(orbit-v2 DDL as reference), archive excluded, drift test realizes the
DB-side check dcy-001 OQ-2 deferred.
Scope defers broker execution, safety floor, and strategy daemons to a
follow-up Discovery. Confirmed By Justin.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Implement REQ-001~004 (dcy-001): scaffold the trex-core package
(pyproject, trex_core/, tests/), port the slot pure domain into
trex_core.domain.slot with import rewrites, add the EXPECTED_SLOT_FIELDS
contract guard (test_contract), and port the state/service unit tests.
Verification: 56 passed, ruff clean, import sweep shows zero external
deps, public __all__ exposes no infra symbols, contract negative case
reproduced. Align project-structure/runtime-flows baselines to the real
tree. Sync SDLC tracking: REQ-001~004 → Implemented, BAT-001 →
release-candidate.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolve scope/toolchain CONFIRM items (operator-confirmed), check off
remaining handoff items, and flip Freeze flags (Handoff 승인, Ready true,
Confirmed By Justin). Update discovery index row to confirmed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Record the OQ-1 decision (trex_core.domain.slot over app.domain.slot) in
dcy-001 and propagate the planned package path app/ -> trex_core/ across
the structure baseline and bootstrap seed (dist name trex-core).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Remove all references to the gitignored temp/plan.md draft and embed the
Slot column contract it depended on as Appendix A, so the Discovery stays
self-contained after temp/ is deleted.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
First real Discovery after baseline bootstrap. Defines scope, FR/NFR,
risks, and success criteria for bootstrapping the trex-core Python
project and migrating the slot pure domain (no persistence/CLI).
Open questions OQ-1 (package namespace) and OQ-2 (column-contract
anchoring) left for confirm-discovery; handoff held.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>