2025-06-06 20:33:29 +08:00
|
|
|
# Modules Documentation
|
2025-05-31 20:55:52 +08:00
|
|
|
|
2025-06-06 20:33:29 +08:00
|
|
|
This section contains detailed technical documentation for all system modules in the TCP Dashboard platform.
|
2025-05-31 20:55:52 +08:00
|
|
|
|
|
|
|
|
## 📋 Contents
|
|
|
|
|
|
2025-06-04 13:30:16 +08:00
|
|
|
### User Interface & Visualization
|
|
|
|
|
|
2025-06-06 20:33:29 +08:00
|
|
|
- **[Chart System (`charts/`)](./charts/)** - *Comprehensive modular chart system*
|
2025-06-04 13:30:16 +08:00
|
|
|
- **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
|
|
|
|
|
|
2025-05-31 20:55:52 +08:00
|
|
|
### Data Collection System
|
|
|
|
|
|
2025-06-06 20:33:29 +08:00
|
|
|
- **[Data Collectors (`data_collectors.md`)]** - *Comprehensive guide to the enhanced data collector system*
|
2025-05-31 20:55:52 +08:00
|
|
|
- **BaseDataCollector** abstract class with health monitoring
|
|
|
|
|
- **CollectorManager** for centralized management
|
|
|
|
|
- **Exchange Factory Pattern** for standardized collector creation
|
|
|
|
|
- **Modular Exchange Architecture** for scalable implementation
|
|
|
|
|
- Auto-restart and failure recovery mechanisms
|
|
|
|
|
- Health monitoring and alerting systems
|
|
|
|
|
- Performance optimization techniques
|
|
|
|
|
- Integration examples and patterns
|
|
|
|
|
- Comprehensive troubleshooting guide
|
|
|
|
|
|
2025-06-07 12:31:47 +08:00
|
|
|
- **[Data Validation (`validation.md`)]** - *Robust data validation framework*
|
|
|
|
|
- **BaseDataValidator** abstract class for exchange-specific validation
|
|
|
|
|
- **Field Validators** for common market data fields
|
|
|
|
|
- **Validation Results** with error and warning handling
|
|
|
|
|
- **Exchange-Specific Validators** with custom rules
|
|
|
|
|
- Comprehensive test coverage
|
|
|
|
|
- Error handling and sanitization
|
|
|
|
|
- Performance optimization for high-frequency validation
|
|
|
|
|
- Integration examples and patterns
|
|
|
|
|
|
2025-06-02 13:27:01 +08:00
|
|
|
### Database Operations
|
|
|
|
|
|
2025-06-06 20:33:29 +08:00
|
|
|
- **[Database Operations (`database_operations.md`)]** - *Repository pattern for clean database interactions*
|
2025-06-02 13:27:01 +08:00
|
|
|
- **Repository Pattern** implementation for data access abstraction
|
|
|
|
|
- **MarketDataRepository** for candle/OHLCV operations
|
|
|
|
|
- **RawTradeRepository** for WebSocket data storage
|
|
|
|
|
- Automatic transaction management and session cleanup
|
|
|
|
|
- Configurable duplicate handling with force update options
|
|
|
|
|
- Custom error handling with DatabaseOperationError
|
|
|
|
|
- Database health monitoring and performance statistics
|
|
|
|
|
- Migration guide from direct SQL to repository pattern
|
|
|
|
|
|
2025-06-02 13:42:00 +08:00
|
|
|
### Technical Analysis
|
|
|
|
|
|
2025-06-06 20:33:29 +08:00
|
|
|
- **[Technical Indicators (`technical-indicators.md`)]** - *Comprehensive technical analysis module*
|
2025-06-02 13:42:00 +08:00
|
|
|
- **Five Core Indicators**: SMA, EMA, RSI, MACD, and Bollinger Bands
|
|
|
|
|
- **Sparse Data Handling**: Optimized for the platform's aggregation strategy
|
|
|
|
|
- **Vectorized Calculations**: High-performance pandas and numpy implementation
|
|
|
|
|
- **Flexible Configuration**: JSON-based parameter configuration with validation
|
|
|
|
|
- **Integration Ready**: Seamless integration with OHLCV data and real-time processing
|
|
|
|
|
- Batch processing for multiple indicators
|
|
|
|
|
- Support for different price columns (open, high, low, close)
|
|
|
|
|
- Comprehensive unit testing and documentation
|
|
|
|
|
|
2025-05-31 20:55:52 +08:00
|
|
|
### Logging & Monitoring
|
|
|
|
|
|
2025-06-06 20:33:29 +08:00
|
|
|
- **[Enhanced Logging System (`logging.md`)]** - *Unified logging framework*
|
2025-05-31 20:55:52 +08:00
|
|
|
- Multi-level logging with automatic cleanup
|
|
|
|
|
- Console and file output with formatting
|
|
|
|
|
- Performance monitoring integration
|
|
|
|
|
- Cross-component logging standards
|
|
|
|
|
- Log aggregation and analysis
|
|
|
|
|
|
|
|
|
|
## 🔧 Component Architecture
|
|
|
|
|
|
|
|
|
|
### Core Components
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
┌─────────────────────────────────────────────────────────────┐
|
2025-06-04 13:30:16 +08:00
|
|
|
│ TCP Dashboard Platform │
|
|
|
|
|
│ │
|
2025-05-31 20:55:52 +08:00
|
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
2025-06-04 13:30:16 +08:00
|
|
|
│ │ Modular Dashboard System │ │
|
|
|
|
|
│ │ • Separated layouts, callbacks, components │ │
|
|
|
|
|
│ │ • Chart layers with strategy management │ │
|
|
|
|
|
│ │ • Real-time indicator updates │ │
|
|
|
|
|
│ │ • User indicator CRUD operations │ │
|
2025-05-31 20:55:52 +08:00
|
|
|
│ └─────────────────────────────────────────────────────┘ │
|
|
|
|
|
│ │ │
|
2025-06-04 13:30:16 +08:00
|
|
|
│ ┌─────────────────────────────────────────────────────┐ │
|
|
|
|
|
│ │ 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 │ │ │
|
|
|
|
|
│ │ └─────────────┘ └─────────────┘ └────────────────┘ │ │
|
|
|
|
|
│ └─────────────────────────────────────────────────────┘ │
|
2025-05-31 20:55:52 +08:00
|
|
|
└─────────────────────────────────────────────────────────────┘
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Design Patterns
|
|
|
|
|
|
2025-06-04 13:30:16 +08:00
|
|
|
- **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
|
2025-05-31 20:55:52 +08:00
|
|
|
- **Singleton Pattern**: Centralized logging and configuration management
|
2025-06-04 13:30:16 +08:00
|
|
|
- **Modular Architecture**: Separated concerns with reusable components
|
|
|
|
|
- **Repository Pattern**: Clean database access abstraction
|
2025-05-31 20:55:52 +08:00
|
|
|
|
|
|
|
|
## 🚀 Quick Start
|
|
|
|
|
|
2025-06-04 13:30:16 +08:00
|
|
|
### 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
|
2025-05-31 20:55:52 +08:00
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
# Data Collector usage
|
|
|
|
|
from data.exchanges import create_okx_collector
|
|
|
|
|
from data.base_collector import DataType
|
|
|
|
|
|
|
|
|
|
collector = create_okx_collector(
|
|
|
|
|
symbol='BTC-USDT',
|
|
|
|
|
data_types=[DataType.TRADE, DataType.ORDERBOOK]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Logging usage
|
|
|
|
|
from utils.logger import get_logger
|
|
|
|
|
|
|
|
|
|
logger = get_logger("my_component")
|
|
|
|
|
logger.info("Component initialized")
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Component Integration
|
|
|
|
|
|
|
|
|
|
```python
|
|
|
|
|
# Integrating multiple components
|
|
|
|
|
from data.collector_manager import CollectorManager
|
2025-06-04 13:30:16 +08:00
|
|
|
from dashboard.app import create_app
|
2025-05-31 20:55:52 +08:00
|
|
|
from utils.logger import get_logger
|
|
|
|
|
|
2025-06-04 13:30:16 +08:00
|
|
|
# Start data collection
|
2025-05-31 20:55:52 +08:00
|
|
|
manager = CollectorManager("production_system")
|
2025-06-04 13:30:16 +08:00
|
|
|
|
|
|
|
|
# Create dashboard app
|
|
|
|
|
app = create_app()
|
2025-05-31 20:55:52 +08:00
|
|
|
|
|
|
|
|
# Components work together seamlessly
|
|
|
|
|
await manager.start()
|
2025-06-04 13:30:16 +08:00
|
|
|
app.run_server(host='0.0.0.0', port=8050)
|
2025-05-31 20:55:52 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 📊 Performance & Monitoring
|
|
|
|
|
|
|
|
|
|
### Health Monitoring
|
|
|
|
|
|
|
|
|
|
All components include built-in health monitoring:
|
|
|
|
|
|
|
|
|
|
- **Real-time Status**: Component state and performance metrics
|
|
|
|
|
- **Auto-Recovery**: Automatic restart on failures
|
|
|
|
|
- **Performance Tracking**: Message rates, uptime, error rates
|
|
|
|
|
- **Alerting**: Configurable alerts for component health
|
2025-06-04 13:30:16 +08:00
|
|
|
- **Dashboard Integration**: Visual system health monitoring
|
2025-05-31 20:55:52 +08:00
|
|
|
|
|
|
|
|
### Logging Integration
|
|
|
|
|
|
|
|
|
|
Unified logging across all components:
|
|
|
|
|
|
|
|
|
|
- **Structured Logging**: JSON-formatted logs for analysis
|
|
|
|
|
- **Multiple Levels**: Debug, Info, Warning, Error levels
|
|
|
|
|
- **Automatic Cleanup**: Log rotation and old file cleanup
|
|
|
|
|
- **Performance Metrics**: Built-in performance tracking
|
2025-06-04 13:30:16 +08:00
|
|
|
- **Component Isolation**: Separate loggers for different modules
|
2025-05-31 20:55:52 +08:00
|
|
|
|
|
|
|
|
## 🔗 Related Documentation
|
|
|
|
|
|
2025-06-06 20:33:29 +08:00
|
|
|
- **[Dashboard Modular Structure (dashboard-modular-structure.md)](./dashboard-modular-structure.md)** - Complete dashboard architecture
|
|
|
|
|
- **[Exchange Documentation (exchanges/)](./exchanges/)** - Exchange-specific implementations
|
|
|
|
|
- **[Architecture Overview (`../../architecture.md`)]** - System design and patterns
|
|
|
|
|
- **[Setup Guide (`../../guides/setup.md`)]** - Component configuration and deployment
|
|
|
|
|
- **[API Reference (`../../reference/`)** - Technical specifications
|
2025-05-31 20:55:52 +08:00
|
|
|
|
|
|
|
|
## 📈 Future Components
|
|
|
|
|
|
|
|
|
|
Planned component additions:
|
|
|
|
|
|
2025-06-04 13:30:16 +08:00
|
|
|
- **Signal Layer**: Bot trading signal visualization and integration
|
2025-05-31 20:55:52 +08:00
|
|
|
- **Strategy Engine**: Trading strategy execution framework
|
|
|
|
|
- **Portfolio Manager**: Position and risk management
|
|
|
|
|
- **Alert Manager**: Advanced alerting and notification system
|
|
|
|
|
- **Data Analytics**: Historical data analysis and reporting
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
2025-06-06 20:33:29 +08:00
|
|
|
*For the complete documentation index, see the [main documentation README (`../README.md`)]*
|