init
This commit is contained in:
159
tasks/prd-crypto-bot-dashboard.md
Normal file
159
tasks/prd-crypto-bot-dashboard.md
Normal file
@@ -0,0 +1,159 @@
|
||||
# Product Requirements Document: Crypto Trading Bot Dashboard
|
||||
|
||||
## Introduction/Overview
|
||||
|
||||
Create a simple control dashboard for managing and monitoring multiple cryptocurrency trading bots simultaneously. The system will allow testing different strategies in parallel using real OKX market data and virtual trading simulation. The focus is on rapid implementation to enable strategy testing within days rather than weeks.
|
||||
|
||||
**Core Problem**: Currently, testing multiple trading strategies requires manual coordination and lacks real-time monitoring capabilities. There's no unified way to compare strategy performance or manage multiple bots running simultaneously.
|
||||
|
||||
## Goals
|
||||
|
||||
1. **Enable Parallel Strategy Testing**: Run up to 5 different trading bots simultaneously with different strategies
|
||||
2. **Real-time Monitoring**: Visualize bot performance, trading decisions, and market data in real-time
|
||||
3. **Quick Strategy Validation**: Reduce the time from strategy implementation to performance assessment
|
||||
4. **Historical Analysis**: Enable backtesting with previously collected market data
|
||||
5. **Operational Control**: Simple start/stop functionality for individual bots
|
||||
|
||||
## User Stories
|
||||
|
||||
1. **As a strategy developer**, I want to start multiple bots with different strategies so that I can compare their performance over the same time period.
|
||||
|
||||
2. **As a trader**, I want to see real-time price charts and bot decisions so that I can understand how my strategies are performing.
|
||||
|
||||
3. **As an analyst**, I want to view historical performance metrics so that I can evaluate strategy effectiveness over different market conditions.
|
||||
|
||||
4. **As a system operator**, I want to stop underperforming bots so that I can prevent further virtual losses.
|
||||
|
||||
5. **As a researcher**, I want to run backtests on historical data so that I can validate strategies before live testing.
|
||||
|
||||
## Functional Requirements
|
||||
|
||||
### Core Bot Management
|
||||
1. **Bot Lifecycle Control**: System must allow starting and stopping individual bots via web interface
|
||||
2. **Multi-Bot Support**: System must support running up to 5 bots simultaneously
|
||||
3. **Bot Configuration**: System must read bot configurations from JSON/YAML files in a configs directory
|
||||
4. **Status Monitoring**: System must display current status (running/stopped) for each configured bot
|
||||
|
||||
### Data Management
|
||||
5. **Market Data Integration**: System must connect to existing OKX data feed and display real-time price information
|
||||
6. **Trading Decision Storage**: System must record all bot trading decisions (buy/sell signals, amounts, timestamps) to database
|
||||
7. **Performance Tracking**: System must calculate and store key metrics (balance, profit/loss, number of trades) for each bot
|
||||
8. **Data Persistence**: System must use SQLite for simplicity with separate tables for market data and bot decisions
|
||||
|
||||
### User Interface
|
||||
9. **Dashboard Layout**: System must provide a single-page dashboard showing all bot information
|
||||
10. **Price Visualization**: System must display candlestick charts with bot buy/sell markers overlaid
|
||||
11. **Bot Switching**: System must allow switching chart view between different active bots
|
||||
12. **Performance Metrics**: System must show current balance, total profit/loss, and trade count for each bot and trade time
|
||||
13. **Real-time Updates**: System must refresh data every 2 seconds minimum
|
||||
|
||||
### Backtesting
|
||||
14. **Historical Mode**: System must allow running bots against historical market data
|
||||
15. **Time Range Selection**: System must provide date range picker for backtest periods
|
||||
16. **Accelerated Testing**: System must support running backtests faster than real-time
|
||||
|
||||
## Non-Goals (Out of Scope)
|
||||
|
||||
- **Multi-exchange Support**: Only OKX integration for MVP
|
||||
- **Real Money Trading**: Virtual trading simulation only
|
||||
- **Advanced UI/UX**: Basic functional interface, not polished design
|
||||
- **User Authentication**: Single-user system for MVP
|
||||
- **Strategy Editor**: Strategy creation/editing via code only, not UI
|
||||
- **Advanced Analytics**: Complex statistical analysis beyond basic P&L
|
||||
- **Mobile Interface**: Desktop web interface only
|
||||
- **High-frequency Trading**: Strategies with sub-second requirements not supported
|
||||
|
||||
## Technical Considerations
|
||||
|
||||
### Technology Stack
|
||||
- **Backend**: Python with existing OKX, strategy, and trader modules
|
||||
- **Frontend**: Plotly Dash for rapid development and Python integration
|
||||
- **Database**: PostgreSQL, SQLAlchemy
|
||||
- **Communication**: Direct database polling (no WebSockets for MVP)
|
||||
|
||||
### Architecture Simplicity
|
||||
- **Monolithic Design**: Single Python application with all components
|
||||
- **File-based Configuration**: JSON files for bot settings
|
||||
- **Polling Updates**: 2-second refresh cycle acceptable for MVP
|
||||
- **Process Management**: Simple threading or multiprocessing for bot execution
|
||||
|
||||
### Integration Requirements
|
||||
- **Existing Module Refactoring**: May need to modify current strategy and trader modules for unified signal processing
|
||||
- **Database Schema**: Design simple schema for bot decisions and performance metrics
|
||||
- **Error Handling**: Basic error logging and bot restart capabilities
|
||||
|
||||
## Success Metrics
|
||||
|
||||
1. **Functionality**: Successfully run 3+ bots simultaneously for 24+ hours without crashes
|
||||
2. **Data Completeness**: Capture 100% of trading decisions and market data during bot operation
|
||||
3. **Performance Visibility**: Display real-time bot performance with <5 second update latency
|
||||
4. **Backtesting Capability**: Run historical tests covering 1+ weeks of data in <10 minutes
|
||||
5. **Operational Control**: Start/stop bots with <10 second response time
|
||||
|
||||
## Design Considerations
|
||||
|
||||
### Dashboard Layout
|
||||
```
|
||||
+------------------+-------------------+
|
||||
| Bot Controls | Active Charts |
|
||||
| [Bot1] [Start] | |
|
||||
| [Bot2] [Stop] | Price/Strategy |
|
||||
| [Bot3] [Start] | Chart |
|
||||
+------------------+-------------------+
|
||||
| Performance Metrics |
|
||||
| Bot1: +$50 Bot2: -$20 Bot3: +$35 |
|
||||
+--------------------------------------+
|
||||
```
|
||||
|
||||
### Configuration Example
|
||||
```json
|
||||
{
|
||||
"bot_id": "ema_crossover_01",
|
||||
"strategy": "EMA_Crossover",
|
||||
"parameters": {
|
||||
"fast_period": 12,
|
||||
"slow_period": 26,
|
||||
"symbol": "BTC-USDT"
|
||||
},
|
||||
"virtual_balance": 10000
|
||||
}
|
||||
```
|
||||
|
||||
## Implementation Phases
|
||||
|
||||
### Phase 1 (Week 1-2): Core Infrastructure
|
||||
- Set up basic Dash application
|
||||
- Integrate existing OKX data feed
|
||||
- Create bot manager for start/stop functionality
|
||||
- Basic database schema for trading decisions
|
||||
|
||||
### Phase 2 (Week 3): Visualization
|
||||
- Implement price charts with Plotly
|
||||
- Add bot decision overlays
|
||||
- Create performance metrics dashboard
|
||||
- Bot switching functionality
|
||||
|
||||
### Phase 3 (Week 4): Testing & Refinement
|
||||
- Add backtesting capability
|
||||
- Implement error handling and logging
|
||||
- Performance optimization
|
||||
- User acceptance testing
|
||||
|
||||
## Open Questions
|
||||
|
||||
1. **Strategy Module Integration**: What modifications are needed to current strategy modules for unified signal processing?
|
||||
2. **Database Migration**: Start with PostgreSQL
|
||||
3. **Bot Resource Management**: How should we handle memory/CPU limits for individual bots?
|
||||
4. **Configuration Management**: Bot can have hot reloading (we can save current active, paused bots so on start it restore last state.)
|
||||
5. **Error Recovery**: On bot crash system should restart it if it is active.
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- [ ] Start 5 different bots simultaneously via web interface
|
||||
- [ ] View real-time price charts with buy/sell decision markers
|
||||
- [ ] Switch between different bot views in the dashboard
|
||||
- [ ] See current virtual balance and P&L for each bot
|
||||
- [ ] Stop/start individual bots without affecting others
|
||||
- [ ] Run backtest on 1 week of historical data
|
||||
- [ ] System operates continuously for 48+ hours without manual intervention
|
||||
- [ ] All trading decisions logged to database with timestamps
|
||||
78
tasks/tasks-prd-crypto-bot-dashboard.md
Normal file
78
tasks/tasks-prd-crypto-bot-dashboard.md
Normal file
@@ -0,0 +1,78 @@
|
||||
## Relevant Files
|
||||
|
||||
- `app.py` - Main Dash application entry point and layout definition
|
||||
- `bot_manager.py` - Core bot lifecycle management and orchestration
|
||||
- `database/models.py` - SQLAlchemy models for bots, trades, and market data
|
||||
- `database/connection.py` - Database connection and session management
|
||||
- `data/okx_integration.py` - OKX API connection and real-time data feed
|
||||
- `strategies/` - Directory containing strategy modules (existing, may need refactoring)
|
||||
- `trader/` - Directory containing virtual trading logic (existing, may need refactoring)
|
||||
- `components/dashboard.py` - Dash dashboard components and layout
|
||||
- `components/charts.py` - Plotly chart components for price and performance visualization
|
||||
- `backtesting/engine.py` - Backtesting execution engine
|
||||
- `config/bot_configs/` - Directory for JSON bot configuration files
|
||||
- `utils/logging.py` - Logging configuration and utilities
|
||||
- `requirements.txt` - Python dependencies using UV package manager
|
||||
|
||||
### Notes
|
||||
|
||||
- Use docker for development and database
|
||||
- Use UV for package management as specified in project requirements
|
||||
- PostgreSQL with SQLAlchemy for database persistence
|
||||
- Plotly Dash for rapid UI development
|
||||
- Bot configurations stored as JSON files in config directory
|
||||
- System should support hot-reloading of bot states
|
||||
|
||||
## Tasks
|
||||
|
||||
- [ ] 0.0 Dev environment and Docker setup
|
||||
- [ ] 0.1 Create Docker Compose file with PostgreSQL service
|
||||
- [ ] 0.2 Set up UV package management with pyproject.toml dependencies
|
||||
- [ ] 0.3 Create .env file template for database and API configuration
|
||||
- [ ] 0.4 Add development scripts for starting/stopping services
|
||||
- [ ] 0.5 Test database connection and basic container orchestration
|
||||
|
||||
- [ ] 1.0 Database Infrastructure Setup
|
||||
- [ ] 1.1 Design PostgreSQL schema for bots, trades, market_data, and bot_states tables
|
||||
- [ ] 1.2 Create SQLAlchemy models in `database/models.py` for all entities
|
||||
- [ ] 1.3 Implement database connection management in `database/connection.py`
|
||||
- [ ] 1.4 Create Alembic migration scripts for initial schema
|
||||
- [ ] 1.5 Add database utility functions for common queries
|
||||
- [ ] 1.6 Implement bot state persistence for hot-reloading capability
|
||||
|
||||
- [ ] 2.0 Bot Management System Development
|
||||
- [ ] 2.1 Create `bot_manager.py` with BotManager class for lifecycle control
|
||||
- [ ] 2.2 Implement bot configuration loading from JSON files in `config/bot_configs/`
|
||||
- [ ] 2.3 Add start/stop functionality for individual bots using threading/multiprocessing
|
||||
- [ ] 2.4 Create bot status tracking and monitoring system
|
||||
- [ ] 2.5 Implement error handling and automatic bot restart on crash
|
||||
- [ ] 2.6 Add bot state persistence to database for system restart recovery
|
||||
- [ ] 2.7 Create unified signal processing interface for strategy integration
|
||||
|
||||
- [ ] 3.0 OKX Integration and Data Pipeline
|
||||
- [ ] 3.1 Create `data/okx_integration.py` with OKX API client
|
||||
- [ ] 3.2 Implement real-time WebSocket connection for market data
|
||||
- [ ] 3.3 Add market data normalization and validation
|
||||
- [ ] 3.4 Create data storage pipeline to PostgreSQL with proper indexing
|
||||
- [ ] 3.5 Implement data feed monitoring and reconnection logic
|
||||
- [ ] 3.6 Add historical data retrieval for backtesting
|
||||
- [ ] 3.7 Test data pipeline with multiple cryptocurrency pairs
|
||||
|
||||
- [ ] 4.0 Dashboard UI and Visualization
|
||||
- [ ] 4.1 Set up basic Dash application structure in `app.py`
|
||||
- [ ] 4.2 Create dashboard layout with bot controls and chart areas
|
||||
- [ ] 4.3 Implement bot control panel in `components/dashboard.py`
|
||||
- [ ] 4.4 Build candlestick charts with buy/sell markers in `components/charts.py`
|
||||
- [ ] 4.5 Add performance metrics display for each bot (balance, P&L, trade count, trade time)
|
||||
- [ ] 4.6 Implement bot switching functionality for chart views
|
||||
- [ ] 4.7 Add real-time data updates with 2-second refresh cycle
|
||||
- [ ] 4.8 Create responsive layout that works on different screen sizes
|
||||
|
||||
- [ ] 5.0 Backtesting System Implementation
|
||||
- [ ] 5.1 Create `backtesting/engine.py` with backtesting framework
|
||||
- [ ] 5.2 Implement historical data loading and time range selection
|
||||
- [ ] 5.3 Add accelerated testing capability (faster than real-time)
|
||||
- [ ] 5.4 Create backtesting results storage and comparison system
|
||||
- [ ] 5.5 Integrate backtesting with dashboard for result visualization
|
||||
- [ ] 5.6 Add date range picker component for backtest periods
|
||||
- [ ] 5.7 Test backtesting with sample strategies on 1+ week datasets
|
||||
Reference in New Issue
Block a user