feat(config): config 디렉터리 기반 설정 관리 (--config-path/--env-file, trex-orb-v1 정합, BAT-026)

REQ-048/010 change-req. `--config` 를 이름으로 해석 + `--config-path <dir>`
(기본 ./config) + resolve_config_toml(슬래시 포함 값은 하위호환 명시 경로).
`.env` 를 config-dir 결정적 해석(--env-file 우선, 없으면 <config_dir>/.env,
CWD 무관) + config/.env.example + .gitignore config/* 허용목록. 운영자 CLI 도
--config-path/--env-file 동일 적용. from_env() legacy 루트 .env 폴백 유지로
완전 하위호환.

단위 23 + 전체 375 passed, ruff clean, 라이브 스모크(name·path 동일).
REQ-048/010 → Implemented.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 23:45:08 +09:00
co-authored by Claude Opus 4.8
parent 6e8e79660c
commit 8b2c26c04c
14 changed files with 531 additions and 32 deletions
+57
View File
@@ -0,0 +1,57 @@
# trex-core shared infrastructure + secrets (12-factor, REQ-010 CHG-20260609-01).
#
# These are SHARED across all per-instance TOML configs in this directory (same
# DB / broker / portfolio-hub / RabbitMQ), so they live here instead of the
# per-instance TOML.
#
# Resolution (trex_core.runtime.config):
# config_dir = --config-path (default ./config)
# --env-file <path> wins, else <config_dir>/.env
# (standalone reads with no config fall back to legacy CWD-relative .env)
# Real exported environment variables ALWAYS take precedence over this file.
# Use --config-path <abs-dir> to stay CWD-independent when launching elsewhere.
#
# Copy this template to `.env` in the same config dir and fill in:
# cp config/.env.example config/.env
# --- Core (required) ---
# psycopg DSN for the PostgreSQL single-writer store.
TREX_POSTGRESQL_DSN=dbname=trex_core host=/var/run/postgresql
# --- Daemon (optional, defaults shown) ---
TREX_TOTAL_SLOTS=10
TREX_EXECUTION_INTERVAL_SEC=1.0
# --- Broker selection (REQ-011/012/013) ---
# 'paper' (deterministic test double, default) | 'kis' (real KIS Open API)
TREX_BROKER=paper
# --- Paper broker tuning (only when TREX_BROKER=paper; for e2e scenarios) ---
# TREX_PAPER_FILL_AFTER_POLLS=0
# TREX_PAPER_QTY_PER_POLL=
# TREX_PAPER_REJECT_SYMBOLS=
# --- KIS broker (only when TREX_BROKER=kis) ---
# 모의투자(sandbox): https://openapivts.koreainvestment.com:29443
# 실계좌(live): https://openapi.koreainvestment.com:9443 (requires TREX_KIS_ALLOW_LIVE=true)
TREX_KIS_BROKER_BASE_URL=https://openapivts.koreainvestment.com:29443
TREX_KIS_BROKER_TIMEOUT=5
TREX_KIS_BROKER_APP_KEY=
TREX_KIS_BROKER_APP_SECRET=
TREX_KIS_BROKER_ACCOUNT_REF=12345678-01
TREX_KIS_ALLOW_LIVE=false
TREX_KIS_REDIS_URL=
# --- portfolio-hub ledger (REQ-017/018/019, BAT-006) ---
# portfolio_hub_token is per-instance and lives in the instance TOML, not here.
TREX_PORTFOLIO_HUB_BASE_URL=
TREX_PORTFOLIO_HUB_TIMEOUT=5
TREX_LEDGER_INTERVAL_SEC=1.0
# --- Snapshot scheduler (REQ-030, BAT-008) ---
TREX_SNAPSHOT_SCHEDULE_KST=07:30
TREX_SNAPSHOT_TICK_SEC=60
# --- RabbitMQ transport (REQ-022, BAT-007) ---
TREX_RABBITMQ_URL=
TREX_RABBITMQ_TIMEOUT=5