# The Ouroboros AI-powered trading agent for global stock markets with self-evolution capabilities. ## Quick Start ```bash # Setup pip install -e ".[dev]" cp .env.example .env # Edit .env with your KIS and Gemini API credentials # Test pytest -v --cov=src # Run (paper trading) python -m src.main --mode=paper ``` ## Telegram Notifications (Optional) Get real-time alerts for trades, circuit breakers, and system events via Telegram. ### Quick Setup 1. **Create bot**: Message [@BotFather](https://t.me/BotFather) on Telegram β†’ `/newbot` 2. **Get chat ID**: Message [@userinfobot](https://t.me/userinfobot) β†’ `/start` 3. **Configure**: Add to `.env`: ```bash TELEGRAM_BOT_TOKEN=1234567890:ABCdefGHIjklMNOpqrsTUVwxyz TELEGRAM_CHAT_ID=123456789 TELEGRAM_ENABLED=true ``` 4. **Test**: Start bot conversation (`/start`), then run the agent **Full documentation**: [src/notifications/README.md](src/notifications/README.md) ### What You'll Get - 🟒 Trade execution alerts (BUY/SELL with confidence) - 🚨 Circuit breaker trips (automatic trading halt) - ⚠️ Fat-finger rejections (oversized orders blocked) - ℹ️ Market open/close notifications - πŸ“ System startup/shutdown status **Fail-safe**: Notifications never crash the trading system. Missing credentials or API errors are logged but trading continues normally. ## Documentation - **[Workflow Guide](docs/workflow.md)** β€” Git workflow policy and agent-based development - **[Command Reference](docs/commands.md)** β€” Common failures, build commands, troubleshooting - **[Architecture](docs/architecture.md)** β€” System design, components, data flow - **[Context Tree](docs/context-tree.md)** β€” L1-L7 hierarchical memory system - **[Testing](docs/testing.md)** β€” Test structure, coverage requirements, writing tests - **[Agent Policies](docs/agents.md)** β€” Prime directives, constraints, prohibited actions ## Core Principles 1. **Safety First** β€” Risk manager is READ-ONLY and enforces circuit breakers 2. **Test Everything** β€” 80% coverage minimum, all changes require tests 3. **Issue-Driven Development** β€” All work goes through Gitea issues β†’ feature branches β†’ PRs 4. **Agent Specialization** β€” Use dedicated agents for design, coding, testing, docs, review ## Project Structure ``` src/ β”œβ”€β”€ broker/ # KIS API client (domestic + overseas) β”œβ”€β”€ brain/ # Gemini AI decision engine β”œβ”€β”€ core/ # Risk manager (READ-ONLY) β”œβ”€β”€ evolution/ # Self-improvement optimizer β”œβ”€β”€ markets/ # Market schedules and timezone handling β”œβ”€β”€ notifications/ # Telegram real-time alerts β”œβ”€β”€ db.py # SQLite trade logging β”œβ”€β”€ main.py # Trading loop orchestrator └── config.py # Settings (from .env) tests/ # 273 tests across 13 files docs/ # Extended documentation ``` ## Key Commands ```bash pytest -v --cov=src # Run tests with coverage ruff check src/ tests/ # Lint mypy src/ --strict # Type check python -m src.main --mode=paper # Paper trading python -m src.main --mode=live # Live trading (⚠️ real money) # Gitea workflow (requires tea CLI) YES="" ~/bin/tea issues create --repo jihoson/The-Ouroboros --title "..." --description "..." YES="" ~/bin/tea pulls create --head feature-branch --base main --title "..." --description "..." ``` ## Markets Supported - πŸ‡°πŸ‡· Korea (KRX) - πŸ‡ΊπŸ‡Έ United States (NASDAQ, NYSE, AMEX) - πŸ‡―πŸ‡΅ Japan (TSE) - πŸ‡­πŸ‡° Hong Kong (SEHK) - πŸ‡¨πŸ‡³ China (Shanghai, Shenzhen) - πŸ‡»πŸ‡³ Vietnam (Hanoi, HCM) Markets auto-detected based on timezone and enabled in `ENABLED_MARKETS` env variable. ## Critical Constraints ⚠️ **Non-Negotiable Rules** (see [docs/agents.md](docs/agents.md)): - `src/core/risk_manager.py` is **READ-ONLY** β€” changes require human approval - Circuit breaker at -3.0% P&L β€” may only be made **stricter** - Fat-finger protection: max 30% of cash per order β€” always enforced - Confidence < 80 β†’ force HOLD β€” cannot be weakened - All code changes β†’ corresponding tests β†’ coverage β‰₯ 80% ## Contributing See [docs/workflow.md](docs/workflow.md) for the complete development process. **TL;DR:** 1. Create issue in Gitea 2. Create feature branch: `feature/issue-N-description` 3. Implement with tests 4. Open PR 5. Merge after review