From 51fd92c5ebb7adddcfee0586b70a9894d1ac0a06 Mon Sep 17 00:00:00 2001 From: TheSiahxyz <164138827+TheSiahxyz@users.noreply.github.com> Date: Wed, 1 Apr 2026 17:39:53 +0900 Subject: docs: comprehensive TODO update with deep analysis findings Critical: multi-symbol bug, snapshot delay, missing env fields, API healthcheck/error handling, alembic creds mismatch High: binance-only WS, backtester config, CI docker builds Medium: test coverage gaps, realized PnL, test warnings --- docs/TODO.md | 180 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 103 insertions(+), 77 deletions(-) (limited to 'docs/TODO.md') diff --git a/docs/TODO.md b/docs/TODO.md index 57c57c8..d8e5e6a 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -5,102 +5,128 @@ ## Current State - **268 tests passing**, lint clean -- 6 microservices (data-collector, strategy-engine, order-executor, portfolio-manager, backtester, api) + CLI + shared library -- 8 trading strategies (RSI, Grid, MACD, Bollinger, EMA Crossover, VWAP, Volume Profile, Combined) -- Operations: SQLAlchemy ORM, Alembic migrations, structlog, Telegram alerts, resilience, Prometheus + Grafana -- Monitoring: Prometheus, Grafana (provisioned dashboard), Loki + Promtail log aggregation -- Security: Bearer token auth on /health and /metrics endpoints -- CI/CD: Gitea Actions workflow, standalone CI script -- REST API: FastAPI with portfolio, orders, strategies endpoints -- Advanced risk: trailing stop-loss, volatility-based position sizing, max open positions -- Multi-exchange: ccxt factory supporting any exchange (Binance, Bybit, OKX, Kraken, etc.) +- 6 microservices + CLI + shared library +- 8 strategies, REST API, Prometheus/Grafana/Loki, CI/CD, multi-exchange, advanced risk --- -## All Completed - -### Critical (Deployment Blockers) -- [x] Alembic 초기 마이그레이션 (6 테이블) -- [x] Docker Compose 헬스체크 포트 노출 (8080-8083) -- [x] numpy 의존성 추가 - -### High Priority -- [x] CLI 명령어 구현 (backtest, strategy, portfolio, data) -- [x] Backtester sys.path 해킹 제거 (STRATEGIES_DIR 환경변수) -- [x] Integration tests (7개) -- [x] Dockerfile 의존성 정리 + PYTHONPATH 설정 - -### Medium Priority -- [x] Edge case tests (30개: zero volume, empty data, extreme values, reset, notifier) -- [x] DB transaction rollback + transaction() context manager -- [x] Portfolio snapshots (주기적 저장 + Telegram 일일 요약) -- [x] Strategy parameter validation (41 tests, 7 strategies) -- [x] VWAP division by zero 버그 수정 - -### Low Priority -- [x] Grafana dashboard provisioning (7-panel trading overview) -- [x] Multi-exchange support (ccxt factory) -- [x] REST API (FastAPI: portfolio, orders, strategies) -- [x] Strategy combination framework (weighted voting) -- [x] Advanced risk management (trailing stop, volatility sizing, position limits) -- [x] Loki + Promtail log aggregation -- [x] CI/CD pipeline (Gitea Actions + scripts/ci.sh) -- [x] Docker E2E test script (scripts/e2e-test.sh) -- [x] Security hardening (bearer token auth on endpoints) +## Critical (기능 오류 — 즉시 수정 필요) + +### 1. Strategy Engine 멀티 심볼 버그 +- **파일:** `services/strategy-engine/src/strategy_engine/main.py:54-63` +- **문제:** `for symbol in config.symbols:` 안에 `while True` 루프가 있어서 첫 번째 심볼만 처리 +- **영향:** BTC/USDT, ETH/USDT, SOL/USDT 설정 시 BTC/USDT만 영원히 처리 +- **수정:** `asyncio.create_task()`로 각 심볼 병렬 처리 + +### 2. Portfolio Snapshot 첫 실행 지연 +- **파일:** `services/portfolio-manager/src/portfolio_manager/main.py:48` +- **문제:** `snapshot_loop()`이 `asyncio.sleep()` 먼저 실행 → 첫 스냅샷이 24시간 후 +- **수정:** 스냅샷을 먼저 찍고 sleep, 또는 시작 시 즉시 한 번 실행 + +### 3. .env.example 누락 필드 +- **파일:** `.env.example` +- **누락:** `RISK_TRAILING_STOP_PCT`, `RISK_MAX_OPEN_POSITIONS`, `RISK_VOLATILITY_LOOKBACK`, `RISK_VOLATILITY_SCALE` +- **수정:** 4개 필드 추가 + +### 4. API 서비스 헬스체크 없음 +- **파일:** `docker-compose.yml` — api 서비스에 `healthcheck` 블록 없음 +- **수정:** curl 기반 healthcheck 추가 + +### 5. API 엔드포인트 에러 처리 없음 +- **파일:** `services/api/src/trading_api/routers/*.py` +- **문제:** DB 연결 실패 시 500 에러 + 스택 트레이스 노출 +- **수정:** try/except + HTTPException으로 적절한 에러 응답 + +### 6. Alembic 하드코딩된 DB 인증정보 +- **파일:** `shared/alembic.ini:3` +- **문제:** `postgresql+asyncpg://postgres:postgres@localhost:5432/trading` — docker-compose는 `trading:trading` 사용 +- **수정:** `DATABASE_URL` 환경변수 우선 참조 (env.py에서 이미 처리하지만 alembic.ini 기본값 불일치) --- -## Future Ideas (Not Planned) +## High Priority (Production 전) -- WebSocket 기반 실시간 대시보드 -- 백테스트 결과 시각화 (matplotlib/plotly 차트) -- 분산 추적 (OpenTelemetry) -- 멀티 타임프레임 전략 -- 머신러닝 기반 시그널 필터 -- 주문 유형 확장 (LIMIT, STOP_LIMIT, OCO) -- Kubernetes 배포 설정 +### 7. Binance WebSocket 전용 문제 +- **파일:** `services/data-collector/src/data_collector/binance_ws.py` +- **문제:** `exchange_id` 설정은 있지만 WebSocket은 Binance 하드코딩 +- **수정:** 거래소별 WebSocket 추상화 또는 ccxt pro의 watchOHLCV 사용 + +### 8. Backtester Config 상속 오류 +- **파일:** `services/backtester/src/backtester/config.py` +- **문제:** `BacktestConfig(BaseSettings)` — 다른 서비스는 `Settings` 상속 +- **수정:** `class BacktestConfig(Settings):`로 변경, 중복 `database_url` 제거 + +### 9. CI에 Docker 빌드 테스트 없음 +- **파일:** `scripts/ci.sh` +- **문제:** pytest + ruff만 실행, Dockerfile 빌드 검증 없음 +- **수정:** `docker compose build` 단계 추가 + +### 10. Health Port 오프셋 문서화 +- **파일:** 각 서비스 main.py +- **문제:** `health_port + 0/1/2/3` 하드코딩, 변경 시 혼란 +- **수정:** 각 서비스별 `HEALTH_PORT` 환경변수 또는 문서화 --- -## Quick Start (개발 환경) +## Medium Priority (안정화) -```bash -# 1. 환경 설정 -cp .env.example .env -# .env에 BINANCE_API_KEY, BINANCE_API_SECRET 입력 +### 11. 테스트 미커버 모듈 +- CLI 명령어 6개 (backtest, data, portfolio, strategy, trade, service) +- API 라우터 3개 (portfolio, orders, strategies) +- BinanceWebSocket 클래스 +- 각 서비스 main.py 실행 루프 -# 2. 의존성 설치 -pip install -e shared/ +### 12. Realized PnL 미추적 +- **파일:** `services/portfolio-manager/src/portfolio_manager/main.py:32` +- **문제:** `realized_pnl=Decimal("0")` 하드코딩 — 실현 손익 미계산 +- **수정:** 매도 시 실현 PnL 누적 → 스냅샷에 반영 -# 3. 인프라 실행 -make infra +### 13. Test Warning 수정 +- **파일:** `shared/tests/test_db.py:315` +- **문제:** `RuntimeWarning: coroutine was never awaited` +- **수정:** `MagicMock()` → `AsyncMock()` -# 4. DB 마이그레이션 -make migrate +### 14. Order Executor last_id 추적 +- **파일:** `services/order-executor/src/order_executor/main.py:92-96` +- **문제:** `last_id`가 실제로 업데이트되지 않음 (항상 "$") +- **영향:** 재시작 시 메시지 유실 가능 +- **수정:** Redis consumer group 사용 또는 last_id 추적 -# 5. 테스트 -make test +--- -# 6. 서비스 실행 -make up +## Future Ideas (미계획) -# 7. API 접근 -curl http://localhost:8000/api/v1/strategies -curl http://localhost:8000/api/v1/portfolio/positions +- WebSocket 기반 실시간 대시보드 +- 백테스트 결과 시각화 (matplotlib/plotly) +- OpenTelemetry 분산 추적 +- 멀티 타임프레임 전략 +- 머신러닝 시그널 필터 +- 주문 유형 확장 (LIMIT, STOP_LIMIT, OCO) +- Kubernetes 배포 +- 알림 채널 확장 (Discord, Slack) +- 백테스트 결과 DB 저장 및 비교 -# 8. 모니터링 -docker compose --profile monitoring up -d -# Grafana: http://localhost:3000 (admin/admin) -# Prometheus: http://localhost:9090 +--- + +## Estimated Effort -# 9. CLI 사용 -trading strategy list -trading backtest run --strategy rsi --symbol BTCUSDT --from 2025-01-01 --to 2025-12-31 -trading portfolio show +| 카테고리 | 예상 작업량 | +|----------|------------| +| Critical (1-6) | 2-3시간 | +| High (7-10) | 4-6시간 | +| Medium (11-14) | 1-2주 | -# 10. E2E 테스트 -make e2e +--- -# 11. CI -make ci +## Quick Start + +```bash +cp .env.example .env # API 키 입력 +pip install -e shared/ # 의존성 설치 +make infra # Redis + PostgreSQL 시작 +make migrate # DB 마이그레이션 +make test # 268 tests 실행 +make up # 서비스 시작 +make e2e # E2E 테스트 +curl localhost:8000/health # API 헬스체크 ``` -- cgit v1.2.3