AI-powered Telegram bot for cryptocurrency trading analysis featuring real-time MEXC market data, ClickHouse data warehouse, VectorBT backtesting engine, machine learning predictions, and agentic AI system.
π Production-ready Python fintech platform for algorithmic trading research and automation.
- Features
- Architecture
- Demo
- Quick Start
- Installation
- Configuration
- Usage
- Project Roadmap
- Technology Stack
- Contributing
- License
- Contact
-
π€ Telegram Bot Interface
- Webhook mode for instant responses (<100ms latency)
- Natural language command processing
- Real-time notifications and alerts
- Multi-user support
-
π CI/CD Pipeline
- Automated deployments via Bitbucket Pipelines
- Zero-downtime updates
- Production-grade infrastructure (Nginx, SSL, systemd)
-
π MEXC Data Pipeline
- Real-time market data ingestion (5-minute intervals)
- Historical data download (18+ months)
- Support for multiple cryptocurrencies
- Trade-by-trade data for order flow analysis
-
ποΈ ClickHouse Data Warehouse
- Optimized columnar storage (10x compression)
- Lightning-fast aggregation queries (<100ms)
- Materialized views for multiple timeframes (1h, 4h, 1d)
- 2+ years data retention
-
π VectorBT Backtesting Engine
- Vectorized strategy testing (100x faster)
- Pre-built strategies (MA crossover, RSI, MACD, Bollinger Bands)
- Parameter optimization
- Performance metrics (Sharpe ratio, max drawdown, win rate)
-
π€ Machine Learning Models
- LSTM price prediction
- Sentiment analysis (news + social media)
- Pattern recognition (chart patterns)
- Risk assessment models
-
π§ Agentic AI System
- Market Analysis Agent
- Sentiment Analysis Agent
- Risk Management Agent
- Signal Generation Agent
- Research Agent
- Orchestrated via LangChain + OpenRouter
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β USER INTERFACE (Telegram) β
β Natural language commands & real-time alerts β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β DATA LAYER (MEXC + ClickHouse) β
β β’ Real-time market data from MEXC API β
β β’ Historical data warehouse (ClickHouse) β
β β’ 5-minute candles β Multiple timeframes β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β ANALYSIS LAYER (VectorBT + ML) β
β β’ Backtesting engine (VectorBT) β
β β’ Technical indicators (RSI, MACD, etc.) β
β β’ ML models for price prediction β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β AI LAYER (Agentic AI System) β
β β’ Multiple specialized agents β
β β’ Sentiment analysis agent β
β β’ Risk management agent β
β β’ Signal generation agent β
β β’ Orchestrated via LangChain β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
fmanalyzerbot/
βββ bot.py # Main Telegram bot
βββ config/
β βββ settings.py # Centralized configuration
β βββ clickhouse_schema.sql # Database schema
βββ services/
β βββ mexc_client.py # MEXC API wrapper
β βββ clickhouse_client.py # Database connector
β βββ data_pipeline.py # ETL logic
β βββ vectorbt_engine.py # Backtesting (Phase 3)
βββ handlers/
β βββ market_commands.py # /analyze, /price
β βββ backtest_commands.py # /backtest, /optimize
βββ models/ # ML models (Phase 4)
βββ agents/ # Agentic AI (Phase 5)
βββ scripts/
βββ download_historical.py
βββ sync_live_data.py
User: /start
Bot: π€ Welcome to FMAnalyzerBot!
I'm your AI-powered crypto trading assistant.
Commands:
/start - Show this message
/ping - Health check
/analyze [SYMBOL] - Market analysis (coming soon)
User: /analyze SOLUSDT
Bot: π SOL/USDT Analysis
ββββββββββββββββ
Price: $145.32 (+2.3%)
Technical: BULLISH π
β’ RSI: 65 (Neutral)
β’ MACD: Bullish crossover
β’ Support: $140 | Resistance: $150
Sentiment: POSITIVE π
β’ News score: 7.5/10
β’ Social: Trending #4
Signal: BUY π’
Confidence: 78%
Entry: $143-$147
(Screenshots coming soon)
- Python 3.9 or higher
- Telegram account
- MEXC account (for API access)
- ClickHouse Cloud account (free trial available)
git clone https://github.com/mohsinds/fmanalyzerbot.git
cd fmanalyzerbotpython3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activatepip install -r requirements.txtcp .env.example .env
nano .env # Edit with your credentialsRequired environment variables:
TELEGRAM_BOT_TOKEN=your_bot_token_from_botfather
CLICKHOUSE_HOST=your_instance.clickhouse.cloud
CLICKHOUSE_PASSWORD=your_password# Polling mode (for development)
python bot.py
# Webhook mode (for production)
python bot.py --webhookOpen Telegram, search for your bot, and send /start!
# 1. Clone repository
git clone https://github.com/mohsinds/fmanalyzerbot.git
cd fmanalyzerbot
# 2. Set up environment
python3 -m venv .venv
source .venv/bin/activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure
cp .env.example .env
# Edit .env with your credentials
# 5. Initialize database
python scripts/init_database.py
# 6. Download historical data (optional)
python scripts/download_historical.py
# 7. Run bot
python bot.pyRecommended: AlmaLinux 9 / Ubuntu 22.04 / Debian 12
# 1. Install system dependencies
sudo dnf install python3 python3-pip nginx certbot # AlmaLinux
# OR
sudo apt install python3 python3-pip nginx certbot # Ubuntu/Debian
# 2. Clone and setup
git clone https://github.com/mohsinds/fmanalyzerbot.git /opt/fmab
cd /opt/fmab
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# 3. Configure systemd service
sudo cp deploy/fmab.service /etc/systemd/system/
sudo systemctl enable fmab
sudo systemctl start fmab
# 4. Setup Nginx + SSL (webhook mode)
sudo cp deploy/nginx.conf /etc/nginx/sites-available/fmab
sudo ln -s /etc/nginx/sites-available/fmab /etc/nginx/sites-enabled/
sudo certbot --nginx -d api.yourdomain.com
sudo systemctl restart nginx
# 5. Verify
sudo systemctl status fmab
sudo journalctl -u fmab -fdocker pull mohsinds/fmanalyzerbot:latest
docker run -d --env-file .env mohsinds/fmanalyzerbotCreate .env file with the following:
# ===== Telegram Bot =====
TELEGRAM_BOT_TOKEN=123456789:AAH_your_token_from_botfather
WEBHOOK_URL=https://api.yourdomain.com/webhook # For webhook mode
PORT=8443 # For webhook mode
ENV=production # or development
# ===== MEXC API =====
MEXC_API_KEY=optional_for_public_data
MEXC_SECRET_KEY=optional_for_public_data
# ===== ClickHouse =====
CLICKHOUSE_HOST=your-instance.clickhouse.cloud
CLICKHOUSE_PORT=8443
CLICKHOUSE_USER=default
CLICKHOUSE_PASSWORD=your_password
CLICKHOUSE_DATABASE=fmanalyzer
# ===== AI / ML (Phase 4+) =====
OPENROUTER_API_KEY=your_openrouter_key
OPENAI_API_KEY=your_openai_key # For embeddings
# ===== Data Pipeline =====
PRIMARY_SYMBOL=SOLUSDT
KLINE_INTERVAL=5m
SYNC_INTERVAL_SECONDS=300Initialize database schema:
python scripts/init_database.pyOr manually execute:
clickhouse-client --host your-host --secure \
--user default --password your_password \
--query "$(cat config/clickhouse_schema.sql)"/start - Welcome message and bot introduction
/help - Show all available commands
/ping - Health check (verify bot is running)
/download [SYMBOL] - Download latest market data
/status - Show database statistics
/query [SYMBOL] [TIMEFRAME] - Query historical data
/analyze [SYMBOL] - AI-powered market analysis
/predict [SYMBOL] - Price prediction
/sentiment [SYMBOL] - Sentiment analysis
/backtest [STRATEGY] [SYMBOL] - Run backtest
/optimize [STRATEGY] - Optimize strategy parameters
/signal [SYMBOL] - Trading signal with confidence score
/risk [POSITION] - Risk assessment for position
/portfolio - View portfolio performance
/alert [SYMBOL] [CONDITION] - Set price alert
from services.mexc_client import MEXCClient
from services.clickhouse_client import ClickHouseClient
# Initialize clients
mexc = MEXCClient()
ch = ClickHouseClient()
# Download historical data
klines = mexc.get_historical_klines(
symbol="SOLUSDT",
interval="5m",
start_date=datetime(2024, 1, 1),
end_date=datetime.now()
)
# Store in ClickHouse
ch.insert_klines("SOLUSDT", klines)
# Query data
df = ch.query_klines(
symbol="SOLUSDT",
start_date="2024-01-01",
end_date="2024-12-31",
interval="1d"
)import vectorbt as vbt
from services.clickhouse_client import ClickHouseClient
# Load data
ch = ClickHouseClient()
data = ch.query_klines("SOLUSDT", "2024-01-01", "2024-12-31", "1h")
# Define strategy
fast_ma = vbt.MA.run(data['close'], 20)
slow_ma = vbt.MA.run(data['close'], 50)
entries = fast_ma.ma_crossed_above(slow_ma)
exits = fast_ma.ma_crossed_below(slow_ma)
# Backtest
portfolio = vbt.Portfolio.from_signals(
data['close'],
entries,
exits,
init_cash=10000,
fees=0.001
)
# Results
print(f"Total Return: {portfolio.total_return():.2%}")
print(f"Sharpe Ratio: {portfolio.sharpe_ratio():.2f}")
print(f"Max Drawdown: {portfolio.max_drawdown():.2%}")Timeline: Weeks 1-2
- Telegram bot setup (polling mode)
- CI/CD pipeline (Bitbucket Pipelines)
- Migration to webhooks (production-ready)
- Server infrastructure (Nginx, SSL, systemd)
- Open-source repository setup
Timeline: Weeks 3-4
- MEXC API integration
- ClickHouse schema design
- Historical data download (18 months)
- Real-time data sync (cron job every 5 min)
- Data quality validation
- Commands:
/download,/status,/query
Timeline: Weeks 5-6
- VectorBT integration
- Pre-built strategies (MA, RSI, MACD, BB)
- Custom strategy builder
- Performance metrics dashboard
- Parameter optimization engine
- Commands:
/backtest,/optimize,/compare
Timeline: Weeks 7-9
- LSTM price prediction model
- Sentiment analysis (news + social media)
- Pattern recognition (chart patterns)
- Risk assessment model
- Model training pipeline
- Commands:
/predict,/sentiment,/forecast
Timeline: Weeks 10-14
- LangChain integration
- OpenRouter API setup
- Market Analysis Agent
- Sentiment Analysis Agent
- Risk Management Agent
- Signal Generation Agent
- Research Agent
- Agent orchestration
- Commands:
/analyze,/signal,/risk,/research
Timeline: Ongoing
- Multi-user portfolio tracking
- Custom alerts system
- Subscription tiers (free/premium)
- Web dashboard (React + FastAPI)
- Paper trading mode
- Real broker integration (via CCXT)
- Multi-asset support (stocks, forex)
- Mobile app (React Native)
| Component | Technology | Version |
|---|---|---|
| Programming Language | Python | 3.9+ |
| Bot Framework | python-telegram-bot | 20.7 |
| Data Source | MEXC API | v3 |
| Database | ClickHouse Cloud | Latest |
| Backtesting | VectorBT | 0.26 |
| ML Framework | TensorFlow | 2.15 |
| AI Orchestration | LangChain | 0.1+ |
| LLM Provider | OpenRouter | Latest |
| Web Server | Nginx | 1.24+ |
| Process Manager | systemd | - |
# Core
python-telegram-bot[webhooks]==20.7
python-dotenv==1.0.1
# Data Pipeline
requests==2.31.0
pandas==2.1.4
numpy==1.26.3
clickhouse-connect==0.7.0
ccxt==4.2.0
# Backtesting
vectorbt==0.26.0
ta-lib==0.4.28
# Machine Learning
tensorflow==2.15.0
scikit-learn==1.4.0
transformers==4.36.0
# Agentic AI
langchain==0.1.0
openai==1.10.0
chromadb==0.4.20Production:
Server: Hetzner Cloud CX21 (2 vCPU, 4GB RAM)
OS: AlmaLinux 9.4
Web Server: Nginx (reverse proxy)
SSL: Let's Encrypt (auto-renewal)
Process Manager: systemd
Database: ClickHouse Cloud (managed)
CI/CD: Bitbucket Pipelines
Development:
IDE: PyCharm / VS Code
Version Control: Git + GitHub
Testing: pytest
Code Quality: black + flake8Contributions are welcome! Please read our Contributing Guidelines first.
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
# Write code # Add tests # Update documentation
- Commit your changes
git commit -m "Add amazing feature" - Push to the branch
git push origin feature/amazing-feature
- Open a Pull Request
- π Bug Fixes: Report or fix bugs
- π Trading Strategies: New VectorBT strategies
- π€ AI Agents: Additional specialized agents
- π Technical Indicators: New indicators
- π Documentation: Improve docs and tutorials
- π Translations: Internationalization
- π¨ UI/UX: Web dashboard improvements
- β Tests: Increase test coverage
We use:
- black for code formatting
- flake8 for linting
- mypy for type checking
Run before committing:
black .
flake8 .
mypy .
pytestThis project is licensed under the MIT License - see the LICENSE file for details.
TL;DR: You can use, modify, and distribute this software freely, even for commercial purposes. Just include the original license and copyright notice.
Mohsin DS
Principal Full-Stack Software Engineer | Founder @ Dimensional Sys Inc.
- πΌ LinkedIn: linkedin.com/in/mohsinds
- π¦ Twitter: @mohsinds
- π§ Email: mohsin@dimensionalsys.com
- π Website: dimensionalsys.com
- π¬ Telegram Bot: @fmanalyzer_bot
- Telegram Bot API - Excellent bot framework
- MEXC Exchange - Free historical data access
- ClickHouse - Lightning-fast analytics database
- VectorBT Community - Backtesting inspiration
- LangChain - Agent framework
- Open Source Community - For making this possible
If you find this project useful, please:
- β Star this repository
- π΄ Fork and contribute
- π’ Share with others
- π Report bugs
- π‘ Suggest features
Built with β€οΈ by developers, for traders
Documentation β’ Report Bug β’ Request Feature