Skip to content

Yusuprozimemet/trading-agent

Repository files navigation

Full Architecture

Full Architecture

Simplified Architecture

Simplified Architecture

Trading Agent - AI-Powered Trading System

πŸ“ Project Purpose & Development Direction

This project was originally built from scratch as a research and educational exploration of AI-driven trading systems.
Through experimentation, it became clear that fully relying on large-scale AI models for real-time trading introduces significant latency and cost challenges, making the system not cost-effective for live production deployment at this stage.

Instead of pushing this system directly into production, the development strategy has shifted toward building lightweight, cost-efficient trading tools https://github.com/Yusuprozimemet/trading-tools β€” with AI being integrated gradually and only where it provides real benefit.
This ensures maintainability, performance, and predictable operating cost as the system evolves.

CI Security

A comprehensive AI-powered trading system built with Microsoft Agent Framework, LangGraph orchestration, and RAG-enhanced decision making. Features microservices architecture with multi-agent trading intelligence.

πŸš€ Quick Start

1. Installation

# Option A: Complete system (production)
pip install -r requirements.txt

# Option B: Minimal setup (local development)
pip install -r requirements/requirements-minimal.txt

# Option C: Specific phase development
pip install -r requirements/requirements-phase2.txt  # Smart Trading
pip install -r requirements/requirements-phase3.txt  # Enhanced Orchestration

2. Basic Setup

# Copy environment template
cp .env.example .env

# Option A: Ultra low-cost deployment (Recommended for learning)
docker-compose -f docker-compose.lite.yml up -d

# Option B: Start core service only (no infrastructure)
cd services/vector_service && python main.py

# Test the system
curl http://localhost:8000/health

3. Deployment Options

# Nano: Ultra low-cost ($5-15/month)
docker-compose -f docker-compose.lite.yml up -d

# Micro: Low cost with cloud DB ($25-50/month)  
docker-compose -f docker-compose.micro.yml up -d

# Full: All services (Higher cost, development)
docker-compose up -d

# Test deployment
curl http://localhost:8000/health

πŸ—οΈ System Architecture

Architecture Notes (as of November 2025)

  • LangChain Service: Fully implemented as a standalone service (not containerized in docker-compose, runs on port 8008 for local development).
  • Trading Service: Multi-tier agent system with robust fallback logic, circuit breaker, and observability. LangChain AI integration is partially implemented.
  • All other services, infrastructure, and observability components are implemented and deployed as described.
  • Kafka topics and ports are current as of this revision.
  • Deployment options (docker-compose, lite, Kubernetes, GCP Terraform) are production-ready and match the codebase.

Three-Phase AI Trading System

Phase Component Purpose Status
Phase 1 LangChain & Vector Services AI/LLM management + RAG capabilities βœ… Operational
Phase 2 Smart Trading & Observability Trading logic + monitoring stack βœ… Operational
Phase 3 Enhanced Multi-Agent Orchestrator Microsoft Agent Framework coordination βœ… Operational

Core Services

  • 🌐 Gateway (8000): API gateway and routing
  • πŸ€– Trading Service (8001): Multi-tier agent system with robust fallback logic, circuit breaker, and observability. LangChain AI integration is partially implemented (core trading logic and circuit breaker are production-ready; advanced LLM-driven features are in progress).
  • πŸ“Š Market Data Service (8002): Real-time and historical market data with resilient data access and fallback logic.
  • ⚑ Vector Service (8006): RAG and semantic search, enhanced vector store (Pinecone, ChromaDB).
  • 🧠 LangChain Service: Standalone AI/LLM management service (not containerized in docker-compose, runs on port 8008 for local development; no dedicated port in compose).
  • 🎯 Orchestrator Service (8007): Multi-agent workflow coordination, enhanced state management (Redis).

πŸ€– AI & System Features

  • 🧠 Microsoft Agent Framework: Multi-agent trading workflows
  • πŸ“š RAG-Enhanced Decisions: Knowledge-augmented trading strategies
  • πŸ”„ LangGraph Orchestration: Complex multi-step trading workflows
  • 🎯 4 Specialized Agents: Market Analyst, Risk Manager, Execution Strategist, Strategy Coordinator
  • πŸ“ˆ 6 Trading Strategies: Momentum, mean reversion, breakout, earnings, sector rotation, risk arbitrage
  • πŸ‘οΈ Complete Observability: End-to-end tracing and monitoring (Prometheus, Jaeger, LangSmith, structured logging)
  • πŸ›‘οΈ Circuit Breaker & Enhanced Error Handling: Implemented for robust service reliability

πŸ“– Documentation

πŸ“‹ Setup & Installation

πŸ”§ Service Documentation

πŸš€ Advanced Topics

πŸ”§ Configuration

Environment Variables

# AI Models (optional for basic functionality)
OPENAI_API_KEY=your-key                    # OpenAI integration
AZURE_OPENAI_ENDPOINT=your-endpoint        # Azure OpenAI  
ANTHROPIC_API_KEY=your-key                 # Anthropic Claude

# Vector Store (ChromaDB works without keys)
VECTOR_STORE_TYPE=chromadb                 # or pinecone
PINECONE_API_KEY=your-key                  # optional cloud vector store

# Trading (for production)
ALPACA_API_KEY=your-key                    # Market data provider
DATABASE_URL=postgresql://...              # Database connection

πŸ“– See Requirements Guide for complete configuration options

πŸ§ͺ Testing

Current Test Status

# Run all tests (149 tests, 37.8% code coverage)
pytest tests/unit/test_phase1_components.py tests/unit/test_phase2_components.py tests/unit/test_phase3_components.py tests/integration/test_complete_system_integration.py -v

# Quick development check
python tests/test_all_components.py

# Specific phase testing
pytest tests/unit/test_phase2_components.py -v  # Smart Trading
pytest tests/unit/test_phase3_components.py -v  # Enhanced Orchestration

⚠️ Testing Limitations

  • Low Coverage: Only 37.8% code coverage (398/1054 lines)
  • Happy-path Focus: Most tests verify basic functionality, not edge cases
  • Mock-heavy: Many tests use simulated data instead of real market conditions
  • Missing Scenarios: No tests for market crashes, API failures, high-frequency conditions
  • No Stress Testing: No performance testing under extreme conditions

Production Testing Requirements

Before live trading, implement:

  • Stress Testing: Market crash scenarios, flash crashes, extreme volatility
  • Performance Testing: High-frequency trading, latency under load, throughput limits
  • Chaos Engineering: Random service failures, network partitions, data corruption
  • Integration Testing: Real broker APIs, actual market data feeds
  • Regression Testing: Historical market events (2008, 2020 crashes, etc.)

πŸ“– See Testing Guide for current testing documentation

πŸš€ Development Deployment

πŸ’° Cost-Effective Options

Nano Tier - Ultra Low Cost ($5-15/month)

# Single container with SQLite - Perfect for learning
docker-compose -f docker-compose.lite.yml up -d

# Or single container deployment
docker build -f Dockerfile.lite -t trading-agent:lite .
docker run -d -p 8000:8000 -v trading_data:/data trading-agent:lite

Infrastructure: SQLite + In-memory cache + Local ChromaDB Suitable for: Learning, paper trading, strategy development

Micro Tier - Low Cost ($25-50/month)

# Essential services with small cloud database
docker-compose -f docker-compose.micro.yml up -d

Infrastructure: Small PostgreSQL + Redis + Basic monitoring Suitable for: Small live trading, personal bots, portfolios <$50k

Full Infrastructure Deployment (Development)

# Build and deploy for development/testing (Higher cost)
docker-compose up --build

# Kubernetes (development environment)
kubectl apply -f kubernetes/

Cloud Deployment Tiers

Tier Cost/Month Infrastructure Use Case
Nano $5-15 SQLite + Local Learning, Paper Trading
Micro $25-50 Small DB + Cache Small Live Trading
Standard $100-300 Managed Services Professional Trading
Enterprise $500+ Full Stack Institutional Use

πŸ“– See Cost-Effective Deployment Guide for detailed cost analysis and optimization strategies

πŸ“– See AI Latency Optimization Guide for solving critical AI performance issues

πŸ“– See Future Implementation Roadmap for what needs to be completed to fix current issues

⚠️ Note: All deployments are for development and testing. Production requires additional security, monitoring, and risk management.

πŸ“Š System Status

βœ… Validation Status

  • All 3 Phases: Locally validated and operational
  • 92 Tests: All passing across unit and integration suites
  • Microsoft Agent Framework: Detected and functional
  • Dependencies: Fully compatible (Python 3.11.14)
  • CI/CD: Enhanced workflows operational

🎯 Development Status

  • Comprehensive test coverage (149 passing tests)
  • Professional documentation structure
  • Organized requirements management
  • Basic error handling and fallbacks

🀝 Contributing

  1. Setup Development Environment:

    pip install -r requirements/requirements.txt
    pip install -r requirements/requirements-dev.txt
  2. Run Tests: pytest tests/ -v

  3. Follow Documentation: See local-development.md

  4. Submit PR: Create feature branch and submit pull request

⚠️ Production Readiness Assessment

Current Status: Educational/Development System

This system is well-architected for learning and development but requires significant implementation work to fix critical issues:

🚨 URGENT: Critical Issues Not Yet Fixed

  • AI Latency: LLM calls (2-15 seconds) still in execution path - dangerous for live trading
  • Cost Risk: Uncontrolled API usage could cost $500-5000+/month
  • Architecture: Fast execution components designed but not integrated
  • Status: See Future Implementation Roadmap for required work

Missing Production Requirements:

  • ❌ Extensive Backtesting: Limited historical data testing with simulated results
  • ❌ Circuit Breakers: No trading halts or emergency stop mechanisms
  • ❌ Position Limits: Basic risk limits (2% per position) but no dynamic enforcement
  • ❌ Real-time Risk Management: Simplified risk calculations, no real-time portfolio monitoring
  • ❌ Market Data Resilience: Basic error handling, no redundant data sources or connection recovery
  • ❌ Edge Case Testing: No tests for market crashes, flash crashes, or extreme volatility
  • ❌ High-Frequency Conditions: No testing under rapid market movements or high-volume scenarios
  • ❌ API Failure Handling: Limited testing of external service failures and timeouts
  • ❌ AI Latency Issues: LLM calls (2-15 seconds) in critical execution path - dangerous for real-time trading
  • ❌ AI Cost Explosion: Potential $500-5000+/month in API costs for frequent trading
  • ❌ Infrastructure Costs: Full stack requires $500-2000+/month for production-grade services
  • ❌ Regulatory Compliance: No compliance checks or audit trails
  • ❌ Stress Testing: No extreme market condition testing
  • ❌ Live Trading Integration: Mock trading implementation only

⚠️ Development Strengths:

  • Microservices architecture with proper separation
  • Basic risk assessment framework
  • Structured logging and monitoring setup
  • AI/ML integration with fallback mechanisms

🚨 Critical Architecture Issues:

  • AI in Execution Path: LLM calls (2-15 seconds) block time-critical trading decisions
  • Cost Explosion Risk: Potential $500-5000+/month in AI API costs
  • No Fast Execution: All trading decisions go through slow AI analysis

⚠️ Testing Reality:

  • 149 tests but only 37.8% code coverage (398/1054 lines covered)
  • Limited edge case coverage: No tests for market crashes, API failures, or data delays
  • No high-frequency testing: No performance or latency testing under load
  • Mostly happy-path tests: Basic functionality verification, minimal error scenarios
  • Mock-heavy testing: Many tests use simulated data rather than real market conditions

πŸ”§ Before Production Use:

  1. Improve Test Coverage: Current 37.8% coverage needs to reach 80%+ for critical paths
  2. Add Edge Case Testing: Market crashes, flash crashes, extreme volatility scenarios
  3. Performance Testing: High-frequency trading conditions, latency under load
  4. API Resilience Testing: External service failures, timeouts, rate limiting
  5. CRITICAL: Separate AI from execution path - Current 2-15 second LLM calls are dangerous
  6. Implement fast execution engine - Target <100ms for trading decisions
  7. Add AI cost controls - Budget limits, caching, scheduled analysis
  8. Implement comprehensive backtesting with real historical data
  9. Add circuit breakers and emergency controls
  10. Enhance real-time risk monitoring and alerts
  11. Add market data redundancy and connection recovery
  12. Implement proper position sizing and exposure limits
  13. Add regulatory compliance checks and audit logging
  14. Conduct stress testing with extreme market scenarios
  15. Replace mock trading with real broker integrations

⚠️ Important Notes

  • Educational Purpose: This system is for educational and research purposes only
  • Development Status: Requires significant production hardening before live trading
  • Paper Trading: Use paper trading exclusively for testing strategies
  • Risk Warning: Not suitable for live trading without extensive additional development
  • Compliance: Ensure compliance with financial regulations before any trading use

πŸ†˜ Support

  • πŸ“š Documentation: docs/ directory for detailed guides
  • πŸ› Issues: GitHub Issues
  • πŸ’¬ Discussions: GitHub Discussions
  • πŸ”§ Quick Scripts: python check_dependencies.py for environment validation

πŸ“„ License

MIT License - see LICENSE file for details.


Built with ❀️ using Microsoft Agent Framework, LangChain, LangGraph, and modern AI technologies.

🎯 Educational/Development System - Requires additional production hardening before live trading.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published