TCPDashboard/dashboard/layouts/market_data.py
Vasily.onl dbe58e5cef Remove deprecated app_new.py and consolidate main application logic into main.py
- Deleted `app_new.py`, which was previously the main entry point for the dashboard application, to streamline the codebase.
- Consolidated the application initialization and callback registration logic into `main.py`, enhancing modularity and maintainability.
- Updated the logging and error handling practices in `main.py` to ensure consistent application behavior and improved debugging capabilities.

These changes simplify the application structure, aligning with project standards for modularity and maintainability.
2025-06-11 18:36:34 +08:00

112 lines
4.5 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
)
from utils.timeframe_utils import load_timeframe_options
logger = get_logger("default_logger")
def _create_dropdown_options(symbols, timeframes):
"""Creates symbol and timeframe dropdown options."""
symbol_options = [{'label': symbol, 'value': symbol} for symbol in symbols]
all_timeframe_options = load_timeframe_options()
available_timeframes_from_db = [tf for tf in [opt['value'] for opt in all_timeframe_options] if tf in timeframes]
if not available_timeframes_from_db:
available_timeframes_from_db = ['5m'] # Default fallback
timeframe_options = [opt for opt in all_timeframe_options if opt['value'] in available_timeframes_from_db]
return symbol_options, timeframe_options
def _load_strategy_and_indicator_options():
"""Loads strategy and indicator options for chart configuration."""
try:
strategy_names = get_available_strategy_names()
strategy_options = [{'label': name.replace('_', ' ').title(), 'value': name} for name in strategy_names]
indicator_manager = get_indicator_manager()
ensure_default_indicators()
overlay_indicators = indicator_manager.get_indicators_by_type('overlay')
subplot_indicators = indicator_manager.get_indicators_by_type('subplot')
overlay_options = []
for indicator in overlay_indicators:
display_name = f"{indicator.name} ({indicator.type.upper()})"
overlay_options.append({'label': display_name, 'value': indicator.id})
subplot_options = []
for indicator in subplot_indicators:
display_name = f"{indicator.name} ({indicator.type.upper()})"
subplot_options.append({'label': display_name, 'value': indicator.id})
return strategy_options, overlay_options, subplot_options
except Exception as e:
logger.warning(f"Market data layout: Error loading indicator options: {e}")
return [{'label': 'Basic Chart', 'value': 'basic'}], [], []
def get_market_data_layout():
"""Create the market data visualization layout with indicator controls."""
symbols = get_supported_symbols()
timeframes = get_supported_timeframes()
symbol_options, timeframe_options = _create_dropdown_options(symbols, timeframes)
strategy_options, overlay_options, subplot_options = _load_strategy_and_indicator_options()
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([
html.H3("💹 Market Data Visualization", style={'color': '#2c3e50', 'margin-bottom': '20px'}),
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_config_panel,
time_range_controls,
export_controls,
dcc.Graph(id='price-chart'),
dcc.Store(id='chart-data-store'),
html.Div(id='market-stats', style={'margin-top': '20px'})
])