Commit Graph
33 Commits
Author SHA1 Message Date
genichinandClaude Opus 4.7 9e64a24441 fix: align portfolio-hub ledger write adapter to live API contract
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>
2026-06-06 11:27:30 +09:00
genichinandClaude Opus 4.7 e24de29335 docs(srs): REQ-027 CHG-04 — correct portfolio-hub read contract for release
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>
2026-06-06 10:41:30 +09:00
genichinandClaude Opus 4.7 515af7a068 docs(srs): REQ-029 CHG-04 — orb-v1 snapshot consumption note
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>
2026-06-06 10:34:40 +09:00
genichinandClaude Opus 4.7 43bad2424e fix: align portfolio-hub read adapter to live API contract
whoami now hits GET /v1/user_info (the live endpoint; /v1/auth/whoami
does not exist), get_portfolios parses the {portfolios:[...],total} envelope
and filters by managed_by_daemon_id client-side (the list endpoint is
token-scoped, no such query param), and a missing URL scheme now defaults
to http:// so a bare host can't silently degrade the daemon.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 10:34:35 +09:00
genichin ca757009f5 feat: add portfolio snapshot read layer 2026-06-06 09:33:00 +09:00
genichin 56e977a7ad update .gitignore 2026-06-06 00:04:07 +09:00
genichin 6c7a1cf6f6 feat: add messaging transport rollout 2026-06-06 00:02:52 +09:00
genichin 4b91343ee8 docs: advance dcy-005 asset snapshot discovery 2026-06-05 22:41:29 +09:00
genichinandClaude Opus 4.8 0d6854aaa5 docs(discovery): add dcy-006 RabbitMQ transport (confirmed) + advance dcy-005
dcy-006 (new, confirmed — Confirmed By: Justin): trex-core ↔ 전략 모듈
통신 transport를 RabbitMQ로 전환. OQ-1~7 전부 Answered —
- HTTP /v1 API 완전 대체(표면 0, healthz 제거; liveness=프로세스 감독)
- 토폴로지: 스냅샷·intent admission = RPC(direct reply-to), 이벤트 = topic
- delivery: at-least-once + idempotency = effectively-once, 스냅샷 reconcile
- degrade: 버퍼링 금지·보수적 중단, core 자율 안전 매도 독립(미구현, 추후)
- 클라이언트: pika 동기 + 스레드 런타임(uvicorn 제거)
- 자격증명: TREX_RABBITMQ_URL

dcy-005 (advance): strategy_id 필터 + 런타임 pause/resume(FR-8/9);
옵션 D(체결 시 portfolio-hub write 응답 cash_balance_after/asset_quantity_after
갱신, portfolio-hub#8); OQ-4 holding 포함·pending/warning/pause 마스킹;
OQ-11 view-mode 파라미터 + OQ-12; 응답 용어 sweep.

index: dcy-006 행 추가(confirmed).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 22:33:42 +09:00
genichin aed54911d4 chore: commit current workspace changes 2026-06-04 23:38:42 +09:00
genichinandClaude Opus 4.8 13837acc60 Implement BAT-006: portfolio-hub ledger integration (REQ-017~019)
- REQ-017: LedgerPort contract (application/ledger_port.py) + portfolio-hub
  adapter + in-memory stub (adapters/ledger/), TREX_PORTFOLIO_HUB_* config
- REQ-018: fill→ledger recording in execution loop; FillStatus carries
  execution_id (deterministic synth) + fee; paper/kis adapters updated
- REQ-019: ledger outbox + retry worker (application/ledger_outbox.py),
  correlation_id idempotency, outcome vocabulary; 002_create_ledger_outbox.sql
- Tests: in-memory/portfolio-hub ledger, execution ledger hook, outbox,
  domain import sweep

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 22:57:31 +09:00
genichinandClaude Opus 4.8 6277d610ea Add dcy-005 Discovery (draft): portfolio-hub asset snapshot read API
- 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>
2026-06-04 22:51:30 +09:00
genichinandClaude Opus 4.8 01a51d0c16 Advance dcy-004 ledger slice: confirm Discovery, draft+approve REQ-017~020, draft BAT-006
- confirm-discovery dcy-004: draft→confirmed (Confirmed By: Justin Ko),
  OQ-1~3 resolved, scope/R-1 accepted, portfolio-hub contract deferred to REQ/delivery
- draft-req: REQ-017 (LedgerPort + portfolio-hub adapter + stub), REQ-018
  (fill→ledger recording + FillStatus exec_id/fee), REQ-019 (ledger outbox
  durability + correlation_id idempotency), REQ-020 (baseline alignment);
  NFR-1~3 absorbed
- confirm-req: REQ-017~020 Proposed→Approved
- draft-batch: BAT-006 (standard) bundling REQ-017~020 from dcy-004
- Update SRS/Discovery/batches indexes

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-04 22:32:27 +09:00
genichinandClaude Opus 4.8 88f5af434b Resolve dcy-004 OQ-1~3 from trex-orbit reference
- OQ-1 asset_id: asset_id == portfolio_id — use the slot's portfolio_id
  directly as the ledger path param (orbit ledger.py / migration 003 /
  coordinator). No symbol mapping or asset lookup.
- OQ-2 durability: ledger outbox (work item) + retry loop, correlation_id
  {asset_id}:{order_id}:{execution_id} dedup, outcome vocabulary
  (completed/duplicate_completed/retryable_failure/conflict_blocked) —
  orbit LedgerWriter pattern; recording decoupled from slot transition.
- OQ-3 exec data: deterministic execution_id (KIS
  kis-daily-ccld:{ord_dt}:{brno}:{odno}:{tot_ccld_qty} / paper synth),
  fee via BrokerPort calculate_fee, tax default 0.

All dcy-004 open questions answered; R-2/R-4 resolved. Remaining gates
(scope-defer confirm, portfolio-hub contract data, Confirmed By) left for
confirm-discovery.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 19:44:00 +09:00
genichinandClaude Opus 4.8 b37b16be93 Add dcy-004 Discovery (draft): portfolio-hub ledger integration
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>
2026-06-04 19:30:38 +09:00
genichin ee4456e7fd update .env.example 2026-06-04 18:57:35 +09:00
genichinandClaude Opus 4.8 ac6061f510 Deliver BAT-005: KIS token Redis cache (REQ-016, minor-change)
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>
2026-06-04 18:44:09 +09:00
genichinandClaude Opus 4.8 97d58318db 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>
2026-06-04 17:46:17 +09:00
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
genichinandClaude Opus 4.8 575ba9f513 Deliver BAT-003: daemon .env loading (REQ-010, minor-change)
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>
2026-06-04 14:56:42 +09:00
genichinandClaude Opus 4.8 a4e263c8e7 Deliver BAT-002: slot-core daemon + HTTP intent API + PostgreSQL
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>
2026-06-04 13:46:08 +09:00
genichinandClaude Opus 4.8 a44f9fddb7 Draft+approve REQ-005~009 from dcy-002 (slot-core daemon + API)
Decompose dcy-002 FR-1~FR-6 into five requirements and promote them to
Approved (gate passed; source dcy-002 confirmed):
- REQ-005 (Installation): slot-core daemon runtime + lifecycle/healthz
- REQ-006 (Data): PostgreSQL SlotRepository + schema + drift test
- REQ-007 (Interface): intent submission API + idempotency
- REQ-008 (Interface): read-only slot/capacity query API
- REQ-009 (Documentation): daemon/API/persistence baseline alignment

NFR-1/2/3 absorbed into REQ-006/007 acceptance. Update SRS index
(Next ID -> REQ-010, register, change log) and dcy-002 created-REQ refs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-04 11:12:34 +09:00
genichinandClaude Opus 4.8 346a580856 Add dcy-002 Discovery (confirmed): slot-core daemon + HTTP intent API
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>
2026-06-04 10:56:08 +09:00
genichinandClaude Opus 4.8 20498aa4ce Deliver BAT-001: bootstrap trex-core + port slot pure domain
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>
2026-06-04 00:16:07 +09:00
genichinandClaude Opus 4.8 8b23b89977 Confirm dcy-001: promote slot-domain Discovery to confirmed
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>
2026-06-03 22:19:30 +09:00
genichinandClaude Opus 4.8 f44b84465a Resolve dcy-001 OQ-1: adopt trex_core.domain.slot namespace
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>
2026-06-03 12:57:52 +00:00
genichinandClaude Opus 4.8 431c1a7bd2 Inline slot column contract in dcy-001, drop temp/plan.md references
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>
2026-06-03 12:48:01 +00:00
genichinandClaude Opus 4.8 0c29a32487 Add dcy-001 Discovery: trex-core base + slot pure-domain migration
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>
2026-06-03 12:42:41 +00:00
genichinandClaude Opus 4.8 b40e569537 Bootstrap StagePilot baseline for slot domain migration
Initialize baseline seed, four baseline docs (project-structure,
runtime-flows, interface-contract, data-model), and the active
discovery/srs/batches/releases indexes. Content derived from the
trex-orbit slot pure-domain migration plan (trex-core as a new base,
pure domain only).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 09:47:14 +00:00
genichinandClaude Opus 4.8 2bb2db1a72 Add SDLC governance scaffolding and Claude/GitHub skills
Add CLAUDE.md governance instructions, .claude command definitions,
and .github skill/instruction set for the Agile iterative SDLC flow.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 08:56:54 +00:00
genichin a9f99f90fd Merge commit '9339d3d503a273316eafa8877032fe978eefd8a1' as '.stage-pilot' 2026-06-03 08:56:02 +00:00
genichin 9339d3d503 Squashed '.stage-pilot/' content from commit 2c0510c
git-subtree-dir: .stage-pilot
git-subtree-split: 2c0510c68add43c50adcdedb30c174e68e730395
2026-06-03 08:56:02 +00:00
genichin 1740bd536a first commit 2026-06-03 08:54:16 +00:00