# FASE 5: PLAN DE EJECUCION REFINADO ## Trading PlatformIA Trading Platform **Fecha:** 2026-01-07 **Basado en:** Analisis, Planeacion, Validacion, Dependencias **Estado:** LISTO PARA EJECUCION --- ## 1. RESUMEN DEL PLAN REFINADO ### 1.1 Objetivo Lograr integracion completa y homologacion de trading-platform en **9 pasos secuenciales** siguiendo el orden de dependencias identificado. ### 1.2 Alcance - Homologar configuraciones - Completar Data Service - Verificar integraciones ML/LLM - Actualizar documentacion - Validar flujos end-to-end ### 1.3 Fuera de Alcance (Diferido) - Testing suite completo - CI/CD Pipeline - Monitoreo Prometheus/Grafana - Marketplace (OQI-009) --- ## 2. PLAN DE EJECUCION DETALLADO ### PASO 1: VERIFICAR DOCKER-COMPOSE **Prioridad:** P0 | **Dependencias:** Ninguna #### 1.1 Archivo: `/docker-compose.yml` **Verificar:** ```yaml services: postgres: ports: ["5432:5432"] environment: POSTGRES_DB: trading_platform POSTGRES_USER: trading POSTGRES_PASSWORD: trading_dev_2025 redis: ports: ["6379:6379"] backend: ports: ["3081:3081"] environment: - DB_HOST=postgres - DB_PORT=5432 - DB_NAME=trading_platform - DB_USER=trading - DB_PASSWORD=trading_dev_2025 - ML_ENGINE_URL=http://ml-engine:3083 - LLM_AGENT_URL=http://llm-agent:3085 frontend: ports: ["3080:3080"] ml-engine: ports: ["3083:3083"] data-service: ports: ["3084:3084"] llm-agent: ports: ["3085:3085"] trading-agents: ports: ["3086:3086"] ``` **Accion:** Verificar que todos los puertos y variables estan correctos. **Validacion:** ```bash docker-compose config --quiet && echo "Config OK" ``` --- ### PASO 2: HOMOLOGAR ARCHIVOS .ENV **Prioridad:** P0 | **Dependencias:** Paso 1 #### 2.1 Backend: `/apps/backend/.env.example` **Contenido homologado:** ```env # Server PORT=3081 NODE_ENV=development # Database DB_HOST=localhost DB_PORT=5432 DB_NAME=trading_platform DB_USER=trading DB_PASSWORD=trading_dev_2025 DB_POOL_MAX=20 DB_SSL=false # Redis REDIS_HOST=localhost REDIS_PORT=6379 # Services ML_ENGINE_URL=http://localhost:3083 LLM_AGENT_URL=http://localhost:3085 DATA_SERVICE_URL=http://localhost:3084 TRADING_AGENTS_URL=http://localhost:3086 # Auth JWT_SECRET=your-jwt-secret-here JWT_EXPIRES_IN=7d # Stripe STRIPE_SECRET_KEY=sk_test_xxx STRIPE_WEBHOOK_SECRET=whsec_xxx ``` #### 2.2 Frontend: `/apps/frontend/.env.example` **Contenido homologado:** ```env # API URLs VITE_API_URL=http://localhost:3081/api/v1 VITE_ML_URL=http://localhost:3083 VITE_LLM_AGENT_URL=http://localhost:3085 # WebSocket VITE_WS_URL=ws://localhost:3081 VITE_ML_WS_URL=ws://localhost:3083 # Features VITE_ENABLE_PAPER_TRADING=true VITE_ENABLE_REAL_TRADING=false ``` #### 2.3 ML Engine: `/apps/ml-engine/.env` **Contenido homologado:** ```env # Server PORT=3083 ENV=development # Database DATABASE_URL=postgresql://trading:trading_dev_2025@localhost:5432/trading_platform # Services DATA_SERVICE_URL=http://localhost:3084 # Models MODELS_PATH=./models ``` #### 2.4 Data Service: `/apps/data-service/.env` **Contenido homologado:** ```env # Server PORT=3084 ENV=development # Database DATABASE_URL=postgresql://trading:trading_dev_2025@localhost:5432/trading_platform # Polygon API POLYGON_API_KEY=f09bA2V7OG7bHn4HxIT6Xs45ujg_pRXk POLYGON_BASE_URL=https://api.polygon.io POLYGON_RATE_LIMIT=5 # Sync SYNC_INTERVAL_MINUTES=5 BACKFILL_DAYS=30 ``` #### 2.5 LLM Agent: `/apps/llm-agent/.env` (CREAR) **Contenido nuevo:** ```env # Server PORT=3085 ENV=development # Services ML_ENGINE_URL=http://localhost:3083 MCP_MT4_URL=http://localhost:3605 MCP_BINANCE_URL=http://localhost:3606 # LLM LLM_PROVIDER=ollama LLM_MODEL=llama3.2 OLLAMA_URL=http://localhost:11434 ``` #### 2.6 Trading Agents: `/apps/trading-agents/.env` (CREAR) **Contenido nuevo:** ```env # Server PORT=3086 ENV=development # Services ML_ENGINE_URL=http://localhost:3083 DATA_SERVICE_URL=http://localhost:3084 # Exchange (Paper Trading) EXCHANGE_MODE=paper INITIAL_BALANCE=100000 ``` **Validacion:** ```bash # Verificar que todas las apps pueden leer sus .env for app in backend frontend ml-engine data-service llm-agent trading-agents; do echo "Checking $app..." test -f apps/$app/.env || test -f apps/$app/.env.example done ``` --- ### PASO 3: VERIFICAR CONFIG BD **Prioridad:** P0 | **Dependencias:** Paso 2 #### 3.1 ML Engine: `/apps/ml-engine/config/database.yaml` **Verificar:** ```yaml postgres: host: ${DB_HOST:-localhost} port: ${DB_PORT:-5432} database: ${DB_NAME:-trading_platform} user: ${DB_USER:-trading} password: ${DB_PASSWORD:-trading_dev_2025} pool_size: 10 max_overflow: 20 # MySQL remoto (solo lectura historicos) mysql: host: "72.60.226.4" port: 3306 user: "root" password: "AfcItz2391,." database: "db_trading_meta" pool_size: 5 ``` #### 3.2 Backend Constants **Verificar:** `/apps/backend/src/shared/constants/database.constants.ts` - Schemas correctos - Table names actualizados **Validacion:** ```bash # Test conexion PostgreSQL PGPASSWORD=trading_dev_2025 psql -h localhost -U trading -d trading_platform -c "SELECT 1" ``` --- ### PASO 4: COMPLETAR DATA SERVICE **Prioridad:** P0 | **Dependencias:** Paso 3 #### 4.1 Verificar Polygon Client **Archivo:** `/apps/data-service/src/services/polygon_client.py` **Verificar funciones:** - `get_aggregates(symbol, timeframe, from_date, to_date)` - `get_latest_price(symbol)` - Rate limiting implementado #### 4.2 Verificar Asset Updater **Archivo:** `/apps/data-service/src/services/asset_updater.py` **Verificar:** - Priority queue (CRITICAL > HIGH > MEDIUM > LOW) - Batch processing - Error handling #### 4.3 Verificar Scheduler **Archivo:** `/apps/data-service/src/services/scheduler.py` **Verificar:** - Interval de 5 minutos - Auto-start en boot - Logging de ejecuciones #### 4.4 Verificar API **Archivo:** `/apps/data-service/src/api/main.py` **Endpoints requeridos:** ```python @app.get("/health") @app.get("/api/v1/market/ohlcv/{symbol}") @app.get("/api/v1/market/latest/{symbol}") @app.post("/api/v1/sync/trigger") @app.get("/api/v1/sync/status") ``` **Validacion:** ```bash curl http://localhost:3084/health curl http://localhost:3084/api/v1/market/latest/XAUUSD ``` --- ### PASO 5: VERIFICAR ML ENGINE **Prioridad:** P1 | **Dependencias:** Paso 4 #### 5.1 Data Service Client **Archivo:** `/apps/ml-engine/src/data/data_service_client.py` **Verificar:** - URL configurable desde .env - Timeout handling - Retry logic #### 5.2 Prediction Service **Archivo:** `/apps/ml-engine/src/services/prediction_service.py` **Verificar:** - Carga de modelos correcta - Fallback heuristico funciona - Todos los metodos responden #### 5.3 API **Archivo:** `/apps/ml-engine/src/api/main.py` **Validacion:** ```bash curl http://localhost:3083/health curl "http://localhost:3083/api/amd_phase?symbol=XAUUSD&timeframe=15m" curl "http://localhost:3083/api/range?symbol=XAUUSD&timeframe=15m" ``` --- ### PASO 6: VERIFICAR LLM AGENT **Prioridad:** P1 | **Dependencias:** Paso 5 #### 6.1 ML Analyzer **Archivo:** `/apps/llm-agent/src/services/ml_analyzer.py` **Verificar:** - Conexion a ML Engine - Metodos get_full_analysis, get_quick_signal - Confluence score calculado #### 6.2 MCP Orchestrator **Archivo:** `/apps/llm-agent/src/services/mcp_orchestrator.py` **Verificar:** - Routing por simbolo (XAUUSD→MT4, BTCUSDT→Binance) - Execute trade funciona - Error handling #### 6.3 Routes **Archivo:** `/apps/llm-agent/src/api/routes.py` **Validacion:** ```bash curl http://localhost:3085/health curl -X POST http://localhost:3085/api/v1/predictions/analyze \ -H "Content-Type: application/json" \ -d '{"symbol": "XAUUSD", "timeframe": "15m"}' ``` --- ### PASO 7: VERIFICAR BACKEND CLIENTS **Prioridad:** P1 | **Dependencias:** Paso 6 #### 7.1 ML Engine Client **Archivo:** `/apps/backend/src/shared/clients/ml-engine.client.ts` **Verificar:** - URL desde env - Metodos de prediccion - Error handling #### 7.2 LLM Agent Client **Archivo:** `/apps/backend/src/shared/clients/llm-agent.client.ts` **Verificar:** - URL desde env - Metodos de analisis - Error handling **Validacion:** ```bash curl http://localhost:3081/health curl http://localhost:3081/api/v1/ml/signals/XAUUSD ``` --- ### PASO 8: VERIFICAR FRONTEND **Prioridad:** P1 | **Dependencias:** Paso 7 #### 8.1 Services **Archivos:** - `src/services/trading.service.ts` - `src/services/mlService.ts` - `src/services/llmAgentService.ts` - `src/services/websocket.service.ts` **Verificar:** - URLs desde env - Metodos implementados - Error handling #### 8.2 Stores **Archivos:** - `src/stores/tradingStore.ts` - `src/stores/paymentStore.ts` **Verificar:** - Actions funcionan - Estado se actualiza #### 8.3 WebSocket **Verificar:** - Conexion se establece - Precio updates llegan - ML signals llegan **Validacion:** ```bash # Iniciar frontend cd apps/frontend && npm run dev # Abrir http://localhost:3080 # Verificar: # - Charts cargan # - ML signals aparecen # - WebSocket conectado ``` --- ### PASO 9: ACTUALIZAR DOCUMENTACION **Prioridad:** P2 | **Dependencias:** Paso 8 #### 9.1 OpenAPI Specs **Crear archivos en:** `/docs/api-contracts/openapi/` - `backend.yaml` - `ml-engine.yaml` - `llm-agent.yaml` - `data-service.yaml` #### 9.2 SERVICE-INTEGRATION.md **Actualizar:** `/docs/api-contracts/SERVICE-INTEGRATION.md` - Agregar todos los endpoints - Ejemplos request/response - Flujos de integracion #### 9.3 Arquitectura **Actualizar:** `/docs/00-vision-general/ARQUITECTURA-GENERAL.md` - Reflejar estado actual - Diagrama actualizado #### 9.4 Inventario BD **Verificar:** `/docs/90-transversal/inventarios/DATABASE_INVENTORY.yml` - 8 schemas listados - Tablas actualizadas **Validacion:** ```bash # Verificar OpenAPI validos npx @apidevtools/swagger-cli validate docs/api-contracts/openapi/*.yaml ``` --- ## 3. CHECKLIST DE VALIDACION FINAL ### 3.1 Servicios Funcionando - [ ] PostgreSQL (5432) - [ ] Redis (6379) - [ ] Backend (3081) - [ ] Frontend (3080) - [ ] ML Engine (3083) - [ ] Data Service (3084) - [ ] LLM Agent (3085) - [ ] Trading Agents (3086) ### 3.2 Integraciones Funcionando - [ ] Frontend → Backend API - [ ] Frontend → ML Engine WS - [ ] Backend → PostgreSQL - [ ] ML Engine → Data Service - [ ] LLM Agent → ML Engine - [ ] Data Service → Polygon API - [ ] Data Service → PostgreSQL ### 3.3 Flujos End-to-End - [ ] Login de usuario - [ ] Ver datos de mercado - [ ] Recibir signals ML - [ ] Ejecutar paper trade - [ ] Ver posiciones - [ ] Procesar pago (Stripe test) ### 3.4 Documentacion - [ ] README actualizado - [ ] APIs documentadas - [ ] Configuracion documentada --- ## 4. COMANDOS DE EJECUCION ### 4.1 Iniciar Todo con Docker ```bash cd /home/isem/workspace-v1/projects/trading-platform docker-compose up -d ``` ### 4.2 Iniciar Desarrollo Local ```bash # Terminal 1 - Backend cd apps/backend && npm run dev # Terminal 2 - Frontend cd apps/frontend && npm run dev # Terminal 3 - ML Engine cd apps/ml-engine && python -m uvicorn src.api.main:app --port 3083 # Terminal 4 - Data Service cd apps/data-service && python -m uvicorn src.api.main:app --port 3084 # Terminal 5 - LLM Agent cd apps/llm-agent && python -m uvicorn src.api.main:app --port 3085 ``` ### 4.3 Verificar Todos los Health ```bash for port in 3081 3083 3084 3085 3086; do echo "Port $port: $(curl -s http://localhost:$port/health | head -c 50)" done ``` --- ## 5. CRITERIOS DE EXITO ### 5.1 Integracion Completa Cuando: 1. Todos los servicios inician sin errores 2. Health checks responden OK 3. Flujo de trading funciona end-to-end 4. ML signals se generan y muestran 5. Documentacion refleja estado actual ### 5.2 Metricas de Exito - 0 errores criticos en logs - < 1s latencia en predicciones - WebSocket estable > 1 hora - Documentacion 100% actualizada --- **Plan refinado listo para ejecucion** **Siguiente fase:** FASE 6 - Ejecucion del plan