Version: 1.1
Last Updated: 2026-01-02
- Fixed NoneType comparison error in
TechnicalCalculator.get_weekly_macro_indicators() - Added validation for
golden_weeks_agoanddeath_weeks_agobefore timestamp access - Prevents "'>' not supported between instances of 'NoneType' and 'int'" error with insufficient weekly data
- Validates crossover periods are not None, > 0, and within ohlcv_data array bounds
- Gracefully logs warning when crossover detected but timestamp unavailable
- See
src/analyzer/AGENTS.md→ TechnicalCalculator section for details
- Refactored
AnalysisEngine(src/analyzer/core/analysis_engine.py) to break downanalyze_marketinto modular steps. - Refactored
TechnicalCalculator(src/analyzer/calculations/technical_calculator.py) to break downget_indicatorsinto category-specific methods. - Removed unused
src/analyzer/formatting/technical_analysisdirectory. - Removed unused import in
src/analyzer/pattern_engine/swing_detection.py.
- Removed 276 lines of confirmed dead code across 9 files
- Deleted
src/rag/search/search_utilities.py(entire file unused) - Removed 5 unused response builder functions (discord_interface)
- Removed 7 unused RAG search functions (only coin-based search is active)
- Removed 2 unused data processor functions (analyzer)
- Removed 2 unused exchange info functions (platforms)
- Removed 1 experimental swing detection function (analyzer)
- Removed 2 legacy format utility functions (utils)
- Removed 2 unused timeframe utility functions (utils)
- Fixed duplicate
@classmethoddecorator bug intimeframe_validator.py - See
DEAD_CODE_ANALYSIS.mdandCODE_CLEANUP_TODO.mdfor full details
This repository uses a layered instruction system for AI agents:
- Root
/AGENTS.md(this file): Global project context, universal rules, architecture overview - Nested
/package/AGENTS.md: Subsystem-specific context that extends or overrides root rules .github/instructions/*.instructions.md: GitHub Copilot-specific behaviors (usesapplyTopatterns)
Precedence Rule: Nested instructions override root instructions when conflicts arise. Always check the most specific AGENTS.md file for the code you're working on.
Discord Crypto Analyzer is a Python 3.11+ asyncio-first Discord bot that analyzes cryptocurrency markets using AI (Google AI/OpenRouter/LM Studio), publishes HTML reports to Discord, and manages message lifecycle with automatic cleanup.
- Core: Python 3.11+, asyncio, discord.py 2.6.3
- Data: pandas 2.3.2, numpy 2.2.3, ccxt 4.5.3 (multi-exchange)
- Visualization: plotly 6.3.0, kaleido (chart PNG export)
- AI: google-genai, OpenRouter API, LM Studio (local)
- APIs: CoinGecko, CryptoCompare, Alternative.me (Fear & Greed)
- Storage: JSON files (
data/), SQLite cache (cache/coingecko_cache.db)
- Asyncio-first: Use
async defandawaiteverywhere. Mirrorstart.pyevent-loop setup (WindowsSelectorEventLoopPolicy on Windows) - Initialization order matters: Components initialized in
DiscordCryptoBot.initialize(), torn down in reverse inshutdown() - Inject dependencies: Pass initialized API clients/managers into constructors. Never construct services inside other classes
- Await readiness:
discord_notifier.wait_until_ready(),symbol_manager.initialize()must be awaited before use - Environment Management: ALWAYS use the project's
.venvlocated in the root directory. Never rely on global Python installations.
- Auto-activation: The project is configured via
.vscode/settings.jsonto automatically point to.venv\Scripts\python.exe. - Manual Activation: If the environment is not active, use
. .venv\Scripts\Activate.ps1(PowerShell) or.venv\Scripts\activate.bat(CMD). - Agent Commands: Agents must ensure they use the
.venvinterpreter for all command executions (e.g.,.\.venv\Scripts\python.exe ...).
- No defensive checks: Do NOT use
isinstance,hasattr,getattr. Correct types must be passed from init - Pass correct objects: If uncertain about types, write tests that assert types instead of adding runtime guards
- Let errors surface: Use proper exception handling, not defensive programming
- Comments: Minimal hash comments (
# short note). Prefer expressive function names and docstrings - No backward-compat shims: When refactoring, update all call sites. Delete unused files immediately
- Small focused edits: Follow existing patterns. Keep PRs small and targeted
- OOP best practices: Prefer encapsulation, clear class responsibilities, and proper class design. Use inheritance and polymorphism only when they model the domain effectively; prefer composition over inheritance for flexibility and testability.
- Design patterns: Apply common patterns where they improve clarity and reuse — Factory, Singleton (sparingly), Strategy, Observer, Decorator. Use
@propertyfor computed attributes when appropriate. - Abstraction: Use abstract base classes and abstract properties to define contracts for subsystems; keep implementations injectable for testing.
- Data classes for DTOs: Use
@dataclassfor simple typed data carriers (Candle/OHLCV, IndicatorResult, PatternDetection, AnalysisResult). Preferfrozen=Truefor immutable value objects andslots=Truefor lower memory overhead when many instances are created. - Defaults: Avoid mutable default arguments; use
field(default_factory=...)for lists/dicts. - When to avoid: For bulk numeric operations prefer numpy arrays / pandas DataFrame; dataclasses are for small structured objects passed between components.
.
├── AGENTS.md # This file (global instructions)
├── start.py # Entry point
├── requirements.txt # Python dependencies
├── config/
│ └── config.ini # Public settings
├── keys.env # Secrets (never commit)
├── data/ # JSON data files
├── cache/ # SQLite caches
├── logs/ # Application logs
├── src/
│ ├── app.py # Main bot orchestrator
│ ├── analyzer/ # Market analysis engine → See src/analyzer/AGENTS.md
│ ├── discord_interface/ # Discord bot layer → See src/discord_interface/AGENTS.md
│ ├── html/ # HTML report generation → See src/html/AGENTS.md
│ ├── indicators/ # Technical indicators → See src/indicators/AGENTS.md
│ ├── platforms/ # External integrations → See src/platforms/AGENTS.md
│ ├── rag/ # RAG system → See src/rag/AGENTS.md
│ └── utils/ # Utilities
└── .github/
└── instructions/ # Copilot-specific instructions
For subsystem-specific rules, always consult the relevant AGENTS.md file in that directory.
# Activate virtual environment
.venv\Scripts\Activate.ps1
# Install dependencies
pip install -r requirements.txt
# Run bot
python start.py# Run tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html- Copy
keys.env.exampletokeys.env - Fill in Discord tokens and API keys
- Edit
config/config.inifor public settings
Always follow this workflow when investigating bugs or making changes:
-
Read Architecture Documentation FIRST
- Read the relevant
AGENTS.mdfile for the subsystem you're investigating - Example: Investigating analyzer issues → Read
src/analyzer/AGENTS.md - AGENTS.md documents component responsibilities, data flow, and methods
- This establishes architectural context BEFORE diving into code
- Read the relevant
-
Map Components to Source Files
- Use AGENTS.md to identify which component does what
- Example: Find "ContextBuilder" → Located in
src/analyzer/prompts/context_builder.py - Understand dependencies and how components interact
-
Investigate the Code
- Now search/read the specific source file identified in step 2
- Use grep to find relevant methods or calculations
- Trace data flow through the component
-
Create Test/Proof of Concept
- Write a test script to reproduce the issue
- Compare old behavior vs expected behavior
- Document the root cause
-
Fix the Code
- Make targeted, focused changes
- Update all call sites if changing a method signature
- Test the fix with your test script
-
Update AGENTS.md Documentation
- Document the fix in the AGENTS.md file for that component
- Include what was fixed and why (especially for subtle bugs)
- Update method descriptions if behavior changed
- Example: Document off-by-one fixes, algorithm changes, etc.
-
Verify Synchronization
- Ensure AGENTS.md reflects the actual code implementation
- Check that all cross-referenced AGENTS.md files are consistent
Example Workflow (Timeframe Bug Fix):
- ✅ Read
src/analyzer/AGENTS.md→ Found ContextBuilder responsibility - ✅ Located
src/analyzer/prompts/context_builder.py→ Found build_market_data_section() - ✅ Traced bug in indexing logic
- ✅ Created
test_timeframe_fix.py→ Proved off-by-one error - ✅ Fixed
context_builder.pyline 158 → Changed index from[-candle_count, 4]to[-(candle_count + 1), 4] - ✅ Updated
src/analyzer/AGENTS.md→ Documented bug and fix logic - ✅ Verified both files synchronized
- Never commit
keys.envor any file containing API keys/tokens - Use environment variables for all sensitive configuration
- Validate inputs from Discord commands before processing
- Rate limit API calls to external services
- pylance: Python analysis, imports, syntax errors
- tavily: Web search for crypto/library info
- github_repo: Search the remote
qrak/DiscordCryptoAnalyzerGitHub repository for code examples, historical implementations, PRs, forks, or cross-repo usage; prefer workspace tools (mcp_pylance_*or editor search) for local development. - context7 mcp: Retrieve up-to-date library documentation and code examples (useful for implementing or updating integrations and API usage).
- Forgetting to
awaitinitialization (wait_until_ready(),initialize()) - Re-initializing components passed between subsystems (pass initialized clients)
- Changing provider fallback semantics without updating
config.inidocs - Not respecting message tracking (use
send_message()for auto-tracking)
Do not create summary documents in .md format or any format. All documentation should be maintained in the appropriate AGENTS.md file.
- Subsystem details: Check the relevant
src/*/AGENTS.mdfile - Configuration: See
config/config.iniandkeys.env.example - Troubleshooting: Each
AGENTS.mdhas a troubleshooting section - Contributing: See
CONTRIBUTING.md