Implement modular architecture for Crypto Trading Bot Dashboard
- Introduced a new modular structure for the dashboard, enhancing maintainability and scalability. - Created main application entry point in `app_new.py`, integrating all components and callbacks. - Developed layout modules for market data, bot management, performance analytics, and system health in the `layouts` directory. - Implemented callback modules for navigation, charts, indicators, and system health in the `callbacks` directory. - Established reusable UI components in the `components` directory, including chart controls and indicator modals. - Enhanced documentation to reflect the new modular structure and provide clear usage guidelines. - Ensured all components are under 300-400 lines for better readability and maintainability.
This commit is contained in:
@@ -4,6 +4,18 @@ This section contains detailed technical documentation for all system components
|
||||
|
||||
## 📋 Contents
|
||||
|
||||
### User Interface & Visualization
|
||||
|
||||
- **[Chart Layers System](charts/)** - *Comprehensive modular chart system*
|
||||
- **Strategy-driven Configuration**: 5 professional trading strategies with JSON persistence
|
||||
- **26+ Indicator Presets**: SMA, EMA, RSI, MACD, Bollinger Bands with customization
|
||||
- **User Indicator Management**: Interactive CRUD system with real-time updates
|
||||
- **Modular Dashboard Integration**: Separated layouts, callbacks, and components
|
||||
- **Validation System**: 10+ validation rules with detailed error reporting
|
||||
- **Extensible Architecture**: Foundation for bot signal integration
|
||||
- Real-time chart updates with indicator toggling
|
||||
- Strategy dropdown with auto-loading configurations
|
||||
|
||||
### Data Collection System
|
||||
|
||||
- **[Data Collectors](data_collectors.md)** - *Comprehensive guide to the enhanced data collector system*
|
||||
@@ -56,34 +68,66 @@ This section contains detailed technical documentation for all system components
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────┐
|
||||
│ CollectorManager │
|
||||
│ TCP Dashboard Platform │
|
||||
│ │
|
||||
│ ┌─────────────────────────────────────────────────────┐ │
|
||||
│ │ Global Health Monitor │ │
|
||||
│ │ • System-wide health checks │ │
|
||||
│ │ • Auto-restart coordination │ │
|
||||
│ │ • Performance analytics │ │
|
||||
│ │ Modular Dashboard System │ │
|
||||
│ │ • Separated layouts, callbacks, components │ │
|
||||
│ │ • Chart layers with strategy management │ │
|
||||
│ │ • Real-time indicator updates │ │
|
||||
│ │ • User indicator CRUD operations │ │
|
||||
│ └─────────────────────────────────────────────────────┘ │
|
||||
│ │ │
|
||||
│ ┌─────────────────┐ ┌─────────────────┐ ┌──────────────┐ │
|
||||
│ │ OKX Collector │ │Binance Collector│ │ Custom │ │
|
||||
│ │ │ │ │ │ Collector │ │
|
||||
│ │ • Health Monitor│ │ • Health Monitor│ │ • Health Mon │ │
|
||||
│ │ • Auto-restart │ │ • Auto-restart │ │ • Auto-resta │ │
|
||||
│ │ • Data Validate │ │ • Data Validate │ │ • Data Valid │ │
|
||||
│ └─────────────────┘ └─────────────────┘ └──────────────┘ │
|
||||
│ ┌─────────────────────────────────────────────────────┐ │
|
||||
│ │ CollectorManager │ │
|
||||
│ │ ┌─────────────────────────────────────────────────┐│ │
|
||||
│ │ │ Global Health Monitor ││ │
|
||||
│ │ │ • System-wide health checks ││ │
|
||||
│ │ │ • Auto-restart coordination ││ │
|
||||
│ │ │ • Performance analytics ││ │
|
||||
│ │ └─────────────────────────────────────────────────┘│ │
|
||||
│ │ │ │ │
|
||||
│ │ ┌─────────────┐ ┌─────────────┐ ┌────────────────┐ │ │
|
||||
│ │ │OKX Collector│ │Binance Coll.│ │Custom Collector│ │ │
|
||||
│ │ │• Health Mon │ │• Health Mon │ │• Health Monitor│ │ │
|
||||
│ │ │• Auto-restart│ │• Auto-restart│ │• Auto-restart │ │ │
|
||||
│ │ │• Data Valid │ │• Data Valid │ │• Data Validate │ │ │
|
||||
│ │ └─────────────┘ └─────────────┘ └────────────────┘ │ │
|
||||
│ └─────────────────────────────────────────────────────┘ │
|
||||
└─────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### Design Patterns
|
||||
|
||||
- **Factory Pattern**: Standardized component creation across exchanges
|
||||
- **Observer Pattern**: Event-driven data processing and callbacks
|
||||
- **Strategy Pattern**: Pluggable data processing strategies
|
||||
- **Factory Pattern**: Standardized component creation across exchanges and charts
|
||||
- **Observer Pattern**: Event-driven data processing and real-time updates
|
||||
- **Strategy Pattern**: Pluggable data processing and chart configuration strategies
|
||||
- **Singleton Pattern**: Centralized logging and configuration management
|
||||
- **Modular Architecture**: Separated concerns with reusable components
|
||||
- **Repository Pattern**: Clean database access abstraction
|
||||
|
||||
## 🚀 Quick Start
|
||||
|
||||
### Using Components
|
||||
### Using Chart Components
|
||||
|
||||
```python
|
||||
# Chart system usage
|
||||
from components.charts.config import get_available_strategy_names
|
||||
from components.charts.indicator_manager import get_indicator_manager
|
||||
|
||||
# Get available strategies
|
||||
strategy_names = get_available_strategy_names()
|
||||
|
||||
# Create custom indicator
|
||||
manager = get_indicator_manager()
|
||||
indicator = manager.create_indicator(
|
||||
name="Custom SMA 50",
|
||||
indicator_type="sma",
|
||||
parameters={"period": 50}
|
||||
)
|
||||
```
|
||||
|
||||
### Using Data Components
|
||||
|
||||
```python
|
||||
# Data Collector usage
|
||||
@@ -107,14 +151,18 @@ logger.info("Component initialized")
|
||||
```python
|
||||
# Integrating multiple components
|
||||
from data.collector_manager import CollectorManager
|
||||
from dashboard.app import create_app
|
||||
from utils.logger import get_logger
|
||||
|
||||
# Start data collection
|
||||
manager = CollectorManager("production_system")
|
||||
logger = get_logger("system_manager")
|
||||
|
||||
# Create dashboard app
|
||||
app = create_app()
|
||||
|
||||
# Components work together seamlessly
|
||||
await manager.start()
|
||||
logger.info("System started successfully")
|
||||
app.run_server(host='0.0.0.0', port=8050)
|
||||
```
|
||||
|
||||
## 📊 Performance & Monitoring
|
||||
@@ -127,6 +175,7 @@ All components include built-in health monitoring:
|
||||
- **Auto-Recovery**: Automatic restart on failures
|
||||
- **Performance Tracking**: Message rates, uptime, error rates
|
||||
- **Alerting**: Configurable alerts for component health
|
||||
- **Dashboard Integration**: Visual system health monitoring
|
||||
|
||||
### Logging Integration
|
||||
|
||||
@@ -136,9 +185,11 @@ Unified logging across all components:
|
||||
- **Multiple Levels**: Debug, Info, Warning, Error levels
|
||||
- **Automatic Cleanup**: Log rotation and old file cleanup
|
||||
- **Performance Metrics**: Built-in performance tracking
|
||||
- **Component Isolation**: Separate loggers for different modules
|
||||
|
||||
## 🔗 Related Documentation
|
||||
|
||||
- **[Dashboard Modular Structure](../dashboard-modular-structure.md)** - Complete dashboard architecture
|
||||
- **[Exchange Documentation](../exchanges/)** - Exchange-specific implementations
|
||||
- **[Architecture Overview](../architecture/)** - System design and patterns
|
||||
- **[Setup Guide](../guides/setup.md)** - Component configuration and deployment
|
||||
@@ -148,9 +199,9 @@ Unified logging across all components:
|
||||
|
||||
Planned component additions:
|
||||
|
||||
- **Signal Layer**: Bot trading signal visualization and integration
|
||||
- **Strategy Engine**: Trading strategy execution framework
|
||||
- **Portfolio Manager**: Position and risk management
|
||||
- **Dashboard UI**: Web-based monitoring and control interface
|
||||
- **Alert Manager**: Advanced alerting and notification system
|
||||
- **Data Analytics**: Historical data analysis and reporting
|
||||
|
||||
|
||||
@@ -63,6 +63,13 @@ components/charts/
|
||||
├── builder.py # Main chart builder
|
||||
└── utils.py # Chart utilities
|
||||
|
||||
dashboard/ # Modular dashboard integration
|
||||
├── layouts/market_data.py # Chart layout with controls
|
||||
├── callbacks/charts.py # Chart update callbacks
|
||||
├── components/
|
||||
│ ├── chart_controls.py # Reusable chart controls
|
||||
│ └── indicator_modal.py # Indicator management UI
|
||||
|
||||
config/indicators/
|
||||
└── user_indicators/ # User-created indicators (JSON files)
|
||||
├── sma_abc123.json
|
||||
@@ -70,6 +77,44 @@ config/indicators/
|
||||
└── ...
|
||||
```
|
||||
|
||||
## Dashboard Integration
|
||||
|
||||
The chart system is fully integrated with the modular dashboard structure:
|
||||
|
||||
### Modular Components
|
||||
|
||||
- **`dashboard/layouts/market_data.py`** - Chart layout with strategy selection and indicator controls
|
||||
- **`dashboard/callbacks/charts.py`** - Chart update callbacks with strategy handling
|
||||
- **`dashboard/components/chart_controls.py`** - Reusable chart configuration panel
|
||||
- **`dashboard/components/indicator_modal.py`** - Complete indicator management interface
|
||||
|
||||
### Key Features
|
||||
|
||||
- **Strategy Dropdown**: Auto-loads predefined indicator combinations
|
||||
- **Real-time Updates**: Charts update immediately with indicator changes
|
||||
- **Modular Architecture**: Each component under 300 lines for maintainability
|
||||
- **Separated Concerns**: Layouts, callbacks, and components in dedicated modules
|
||||
|
||||
### Usage in Dashboard
|
||||
|
||||
```python
|
||||
# From dashboard/layouts/market_data.py
|
||||
from components.charts.config import get_available_strategy_names
|
||||
from components.charts.indicator_manager import get_indicator_manager
|
||||
|
||||
# Get available strategies for dropdown
|
||||
strategy_names = get_available_strategy_names()
|
||||
strategy_options = [{'label': name.replace('_', ' ').title(), 'value': name}
|
||||
for name in strategy_names]
|
||||
|
||||
# Get user indicators for checklists
|
||||
indicator_manager = get_indicator_manager()
|
||||
overlay_indicators = indicator_manager.get_indicators_by_type('overlay')
|
||||
subplot_indicators = indicator_manager.get_indicators_by_type('subplot')
|
||||
```
|
||||
|
||||
For complete dashboard documentation, see [Dashboard Modular Structure](../../dashboard-modular-structure.md).
|
||||
|
||||
## User Indicator Management
|
||||
|
||||
The system includes a comprehensive user indicator management system that allows creating, editing, and managing custom technical indicators.
|
||||
|
||||
Reference in New Issue
Block a user