# πŸ“Š Stock Bot System Communication - Quick Reference ## Current System (Active) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ TRADING BOT SYSTEM β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ External APIs Core Services Interface Services β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Demo Data │──────▢│ Market Data │◀──────▢│ Trading β”‚ β”‚ Alpha Vant. β”‚ β”‚ Gateway β”‚ β”‚ Dashboard β”‚ β”‚ Yahoo Fin. β”‚ β”‚ Port: 3001 β”‚ β”‚ Port: 5173 β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Status: βœ… LIVE β”‚ β”‚ Status: βœ… LIVE β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ β–² β–Ό β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ β”‚ Dragonfly Events β”‚β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Cache & Streams β”‚ β”‚ Status: βœ… READYβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## Next Phase (Ready to Implement) ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ EXPANDED TRADING SYSTEM β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Intelligence Services Core Services Interface Services β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Strategy │◀────▢│ Market Data │◀───▢│ Trading β”‚ β”‚ Orchestrator β”‚ β”‚ Gateway β”‚ β”‚ Dashboard β”‚ β”‚ Port: 4001 β”‚ β”‚ Port: 3001 β”‚ β”‚ Port: 5173 β”‚ β”‚ Status: πŸ“‹ PLAN β”‚ β”‚ Status: βœ… LIVE β”‚ β”‚ Status: βœ… LIVE β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–² β”‚ β–² β”‚ β–Ό β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ └──────────────▢│ Dragonfly Event β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚ Stream Hub β”‚ β”‚ Status: βœ… READYβ”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β–² β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ Risk Guardian β”‚ β”‚ Port: 3002 β”‚ β”‚ Status: πŸ“‹ PLAN β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ ``` ## Communication Protocols ### HTTP REST API ``` Client ──── GET/POST ───▢ Server ◀─── JSON ──────── ``` ### WebSocket Real-time ``` Client ◀═══ Stream ═══▢ Server ◀═══ Events ══▢ ``` ### Dragonfly Event Bus ``` Service A ──── Publish ───▢ Dragonfly ──── Subscribe ───▢ Service B ◀─── Confirm ──── ◀─── Events ──── ``` ## Event Types | Event Type | Publisher | Subscribers | Frequency | |------------|-----------|-------------|-----------| | `MARKET_DATA` | Market Data Gateway | Dashboard, Strategy Orchestrator | Every 5s | | `SIGNAL_GENERATED` | Strategy Orchestrator | Risk Guardian, Execution Engine | As needed | | `RISK_ALERT` | Risk Guardian | Dashboard, Alert Manager | As needed | | `PORTFOLIO_UPDATE` | Portfolio Manager | Dashboard, Risk Guardian | On trades | ## Service Status Matrix | Service | Port | Status | Dependencies | Ready to Implement | |---------|------|--------|--------------|-------------------| | Market Data Gateway | 3001 | βœ… Running | Dragonfly, Config | βœ… Complete | | Trading Dashboard | 5173 | βœ… Running | MDG API | βœ… Complete | | Strategy Orchestrator | 4001 | πŸ“‹ Planned | Dragonfly, MDG | βœ… Package Ready | | Risk Guardian | 3002 | πŸ“‹ Planned | Dragonfly, Config | βœ… Package Ready | | Portfolio Manager | 3004 | ⏳ Future | Database, Orders | ❌ Not Started | | Execution Engine | 3003 | ⏳ Future | Brokers, Portfolio | ❌ Not Started | ## Data Flow Summary 1. **Market Data Flow** ``` External APIs β†’ Market Data Gateway β†’ Dragonfly Events β†’ Dashboard β†’ Strategy Orchestrator ``` 2. **Trading Signal Flow** ``` Market Data β†’ Strategy Orchestrator β†’ Trading Signals β†’ Risk Guardian β†’ Execution Engine ``` 3. **Risk Management Flow** ``` All Events β†’ Risk Guardian β†’ Risk Alerts β†’ Alert Manager β†’ Risk Blocks β†’ Strategy Orchestrator ``` 4. **User Interface Flow** ``` WebSocket ← Dashboard β†’ REST API β†’ Services Events ← β†’ Commands β†’ ``` ## Implementation Priority ### Phase 1 (Current) βœ… - [x] Market Data Gateway - [x] Trading Dashboard - [x] Dragonfly Infrastructure - [x] WebSocket Communication ### Phase 2 (Next) πŸ“‹ - [ ] Strategy Orchestrator - [ ] Risk Guardian - [ ] Event-driven Strategy Execution - [ ] Risk Monitoring & Alerts ### Phase 3 (Future) ⏳ - [ ] Portfolio Manager - [ ] Execution Engine - [ ] Broker Integration - [ ] Database Persistence The system is designed for incremental development where each service can be implemented and tested independently while maintaining full system functionality.