stock-bot/docs/system-communication-chart.md
2025-06-02 08:15:20 -04:00

6.9 KiB

📊 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)

  • Market Data Gateway
  • Trading Dashboard
  • Dragonfly Infrastructure
  • 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.