This system provides automated real-time analytics for your Freqtrade cryptocurrency trading bot, processing completed trades and updating 8 comprehensive analytics categories automatically.
π€ Freqtrade Integration: Monitors your Freqtrade database (~/workspace/freqtrade_bot/user_data/tradesv3.sqlite) and generates insights from your trading bot's performance in real-time.
π Complete User Guide | π Freqtrade Integration Guide | π SQL Analytics Guide
./start_production.sh./check_status.sh./stop_production.shThe system automatically updates these 8 analytics categories when new trades complete, each with dedicated SQL files in the /sql/ directory:
- Table:
performance_rankings| SQL:sql/performance_rankings.sql - Purpose: Ranks trading pairs by profitability to identify top performers
- Key Metrics: Win rate, profit percentage, trade count, profit ratios, volume analysis
- Business Value: Identifies which trading pairs generate the most profit and should receive more capital allocation
- Example Insights: "HYPER/USDT has 100% win rate with 3.04% average profit - allocate more funds"
- Table:
risk_metrics| SQL:sql/risk_metrics.sql - Purpose: Tracks risk management effectiveness and portfolio safety
- Key Metrics: Stop-loss triggers, effectiveness percentages, drawdown, Value at Risk (VaR)
- Business Value: Prevents catastrophic losses by monitoring risk levels and stop-loss performance
- Example Insights: "Stop-loss effectiveness is 85% - risk management working well"
- Table:
strategy_performance| SQL:sql/strategy_performance.sql - Purpose: Compares different trading strategies to optimize bot configuration
- Key Metrics: Win rates, profit factors, expectancy, Sharpe ratios, consecutive streaks
- Business Value: Determines which strategies work best and should be prioritized or disabled
- Example Insights: "SampleStrategy outperforms with 93.94% win rate - increase allocation"
- Table:
timing_analysis| SQL:sql/timing_analysis.sql - Purpose: Identifies optimal trading times and market session performance
- Key Metrics: Hourly performance, weekend vs weekday, market session analysis, best/worst hours
- Business Value: Optimizes trading schedules to trade during profitable hours and avoid poor periods
- Example Insights: "Best performance at 14:00-16:00 UTC, worst at 02:00-04:00 UTC"
- Table:
pair_analytics| SQL:sql/pair_analytics.sql - Purpose: Deep-dive analysis of individual currency pair behavior and characteristics
- Key Metrics: Volatility patterns, duration preferences, base/quote currency analysis, efficiency ratios
- Business Value: Tailors trading approach per pair based on their unique characteristics
- Example Insights: "BTC pairs prefer short-term trades, ETH pairs perform better in swing trades"
- Table:
stop_loss_analytics| SQL:sql/stop_loss_analytics.sql - Purpose: Optimizes stop-loss levels and analyzes protection effectiveness
- Key Metrics: Trigger rates, effectiveness percentages, optimal levels, loss prevention analysis
- Business Value: Fine-tunes risk management by optimizing stop-loss levels per pair/strategy
- Example Insights: "Current -5% stop-loss too tight for HYPER/USDT, optimal level is -3%"
- Table:
duration_patterns| SQL:sql/duration_patterns.sql - Purpose: Analyzes trade duration patterns to optimize exit timing strategies
- Key Metrics: Scalp/short-term/day-trade/swing-trade performance, profit-per-hour efficiency
- Business Value: Maximizes profit efficiency by identifying optimal trade duration ranges
- Example Insights: "Short-term trades (1-8h) generate 2.3x more profit per hour than swing trades"
- Table:
bot_health_metrics| SQL:sql/bot_health_metrics.sql - Purpose: Comprehensive system health monitoring with automated alerts
- Key Metrics: Health status (HEALTHY/WARNING/CRITICAL), performance thresholds, diversification metrics
- Business Value: Provides early warning system for performance degradation and system issues
- Example Insights: "Win rate dropped to 45% - WARNING status triggered, review strategy performance"
Each analytics category includes:
- Complete table schemas with proper indexing for performance
- Data population queries compatible with
~/db_dev/trading_test.db - Analysis examples and query templates
- Maintenance scripts for data quality and cleanup
- Direct trades table queries for real-time analysis
# Execute specific analytics category
sqlite3 ~/db_dev/trading_test.db < sql/performance_rankings.sql
# Run all analytics (executed automatically by system)
for sql_file in sql/*.sql; do
sqlite3 ~/db_dev/trading_test.db < "$sql_file"
done- Freqtrade completes trades β
tradesv3.sqlite - Analytics System detects new trades β processes updates
- SQL Scripts populate analytics tables β generates insights
- Health Monitoring evaluates metrics β triggers alerts
- User Queries access insights β inform trading decisions
The system automatically determines health status based on:
- HEALTHY: Win rate β₯70% AND average profit β₯0.5%
- WARNING: Win rate β₯50% AND average profit β₯0%
- CRITICAL: Below warning thresholds
- Primary Database:
~/workspace/freqtrade_bot/user_data/tradesv3.sqlite(Freqtrade database) - Access Method: Direct SQLite connection
- Data Source: Freqtrade Trade Objects stored in SQLite
- MCP Server:
sqlite-trading-testfor external access
- Trade Checks: Every 5 minutes
- Health Checks: Every hour
- Processing: Only when new completed trades detected
- File:
trading_analytics.log - Console: Real-time output
- Format: Timestamp, level, message
Based on your 90 completed trades:
- Overall Win Rate: 86.67% (HEALTHY)
- Average Profit: 0.73% (HEALTHY)
- Total Profit: $39.03
- Best Strategy: SampleStrategy (93.94% win rate, 1.18% avg profit)
- Top Performing Pair: HYPER/USDT (3.04% avg profit, 100% win rate)
tail -f trading_analytics.logscreen -r trading_analytics# Top performing pairs
sqlite3 ~/db_dev/trading_test.db "
SELECT entity_name, profit_pct, win_rate, trade_count
FROM performance_rankings
ORDER BY profit_pct DESC LIMIT 10"
# Strategy comparison
sqlite3 ~/db_dev/trading_test.db "
SELECT strategy_name, win_rate, avg_profit_pct, total_trades
FROM strategy_performance
ORDER BY avg_profit_pct DESC"
# Health status
sqlite3 ~/db_dev/trading_test.db "
SELECT metric_name, metric_value, health_status
FROM bot_health_metrics"βββ trading_analytics_automation_final.py # Main automation engine
βββ start_production.sh # Production starter
βββ stop_production.sh # Production stopper
βββ check_status.sh # Status checker
βββ trading_analytics.log # System logs
βββ venv_analytics/ # Python virtual environment
βββ CLAUDE.md # Development guide
- Check virtual environment:
source venv_analytics/bin/activate - Verify database access:
sqlite3 ~/db_dev/trading_test.db ".tables" - Check dependencies:
pip list | grep schedule
- System only processes trades with
is_open = 0 - Tracks last processed trade ID to avoid duplicates
- Check
analysis_snapshotstable for processing history
- System uses efficient SQL queries with proper indexing
- Clears and recalculates analytics tables for consistency
- Monitors resource usage via status scripts
The system is designed for 24/7 operation:
- Automatic Recovery: Handles database connection errors gracefully
- State Persistence: Tracks last processed trade ID across restarts
- Resource Efficient: Only processes when new trades are detected
- Error Logging: Comprehensive error tracking and reporting
For issues or questions:
- Check logs:
tail -f trading_analytics.log - Verify status:
./check_status.sh - Review database: Query analytics tables directly
- Restart system:
./stop_production.sh && ./start_production.sh
System Status: β Ready for Production Deployment Last Updated: 2025-07-30 Trades Processed: 90 completed trades Analytics Health: All 8 categories operational