TCPDashboard/dashboard/layouts/market_data.py
Vasily.onl c121b469f0 3.9 Enhance chart functionality with indicator management and data export features
- Updated `ChartBuilder` to support dynamic indicator integration, allowing users to specify overlay and subplot indicators for enhanced chart analysis.
- Implemented a new `get_indicator_data` method in `MarketDataIntegrator` for fetching indicator data based on user configurations.
- Added `create_export_controls` in `chart_controls.py` to facilitate data export options (CSV/JSON) for user analysis.
- Enhanced error handling and logging throughout the chart and data analysis processes to improve reliability and user feedback.
- Updated documentation to reflect new features and usage guidelines for indicator management and data export functionalities.
2025-06-06 12:57:35 +08:00

131 lines
5.2 KiB
Python

"""
Market data layout for the dashboard.
"""
from dash import html, dcc
from utils.logger import get_logger
from components.charts import get_supported_symbols, get_supported_timeframes
from components.charts.config import get_available_strategy_names
from components.charts.indicator_manager import get_indicator_manager
from components.charts.indicator_defaults import ensure_default_indicators
from dashboard.components.chart_controls import (
create_chart_config_panel,
create_time_range_controls,
create_export_controls
)
logger = get_logger("default_logger")
def get_market_data_layout():
"""Create the market data visualization layout with indicator controls."""
# Get available symbols and timeframes from database
symbols = get_supported_symbols()
timeframes = get_supported_timeframes()
# Create dropdown options
symbol_options = [{'label': symbol, 'value': symbol} for symbol in symbols]
timeframe_options = [
{'label': "1 Second", 'value': '1s'},
{'label': "5 Seconds", 'value': '5s'},
{'label': "15 Seconds", 'value': '15s'},
{'label': "30 Seconds", 'value': '30s'},
{'label': '1 Minute', 'value': '1m'},
{'label': '5 Minutes', 'value': '5m'},
{'label': '15 Minutes', 'value': '15m'},
{'label': '1 Hour', 'value': '1h'},
{'label': '4 Hours', 'value': '4h'},
{'label': '1 Day', 'value': '1d'},
]
# Filter timeframe options to only show those available in database
available_timeframes = [tf for tf in ['1s', '5s', '15s', '30s', '1m', '5m', '15m', '1h', '4h', '1d'] if tf in timeframes]
if not available_timeframes:
available_timeframes = ['5m'] # Default fallback
timeframe_options = [opt for opt in timeframe_options if opt['value'] in available_timeframes]
# Get available strategies and indicators
try:
strategy_names = get_available_strategy_names()
strategy_options = [{'label': name.replace('_', ' ').title(), 'value': name} for name in strategy_names]
# Get user indicators from the new indicator manager
indicator_manager = get_indicator_manager()
# Ensure default indicators exist
ensure_default_indicators()
# Get indicators by display type
overlay_indicators = indicator_manager.get_indicators_by_type('overlay')
subplot_indicators = indicator_manager.get_indicators_by_type('subplot')
# Create checkbox options for overlay indicators
overlay_options = []
for indicator in overlay_indicators:
display_name = f"{indicator.name} ({indicator.type.upper()})"
overlay_options.append({'label': display_name, 'value': indicator.id})
# Create checkbox options for subplot indicators
subplot_options = []
for indicator in subplot_indicators:
display_name = f"{indicator.name} ({indicator.type.upper()})"
subplot_options.append({'label': display_name, 'value': indicator.id})
except Exception as e:
logger.warning(f"Market data layout: Error loading indicator options: {e}")
strategy_options = [{'label': 'Basic Chart', 'value': 'basic'}]
overlay_options = []
subplot_options = []
# Create components using the new modular functions
chart_config_panel = create_chart_config_panel(strategy_options, overlay_options, subplot_options)
time_range_controls = create_time_range_controls()
export_controls = create_export_controls()
return html.Div([
# Title and basic controls
html.H3("💹 Market Data Visualization", style={'color': '#2c3e50', 'margin-bottom': '20px'}),
# Main chart controls
html.Div([
html.Div([
html.Label("Symbol:", style={'font-weight': 'bold'}),
dcc.Dropdown(
id='symbol-dropdown',
options=symbol_options,
value=symbols[0] if symbols else 'BTC-USDT',
clearable=False,
style={'margin-bottom': '10px'}
)
], style={'width': '48%', 'display': 'inline-block'}),
html.Div([
html.Label("Timeframe:", style={'font-weight': 'bold'}),
dcc.Dropdown(
id='timeframe-dropdown',
options=timeframe_options,
value='1h',
clearable=False,
style={'margin-bottom': '10px'}
)
], style={'width': '48%', 'float': 'right', 'display': 'inline-block'})
], style={'margin-bottom': '20px'}),
# Chart Configuration Panel
chart_config_panel,
# Time Range Controls (positioned under indicators, next to chart)
time_range_controls,
# Export Controls
export_controls,
# Chart
dcc.Graph(id='price-chart'),
# Hidden store for chart data
dcc.Store(id='chart-data-store'),
# Enhanced Market statistics with integrated data analysis
html.Div(id='market-stats', style={'margin-top': '20px'})
])