Refactor indicator management to a data-driven approach

- Introduced dynamic generation of parameter fields and callback handling for indicators, enhancing modularity and maintainability.
- Updated `config_utils.py` with new utility functions to load indicator templates and generate dynamic outputs and states for parameter fields.
- Refactored `indicators.py` to utilize these utilities, streamlining the callback logic and improving user experience by reducing hardcoded elements.
- Modified `indicator_modal.py` to create parameter fields dynamically based on JSON templates, eliminating the need for manual updates when adding new indicators.
- Added documentation outlining the new data-driven architecture for indicators, improving clarity and guidance for future development.

These changes significantly enhance the flexibility and scalability of the indicator system, aligning with project goals for maintainability and performance.
This commit is contained in:
Vasily.onl
2025-06-11 19:09:52 +08:00
parent 89b071230e
commit 3e0e89b826
8 changed files with 406 additions and 249 deletions

View File

@@ -5,7 +5,7 @@ Indicator modal component for creating and editing indicators.
from dash import html, dcc
import dash_bootstrap_components as dbc
from utils.timeframe_utils import load_timeframe_options
from config.indicators.config_utils import get_indicator_dropdown_options, generate_parameter_fields_config
from config.indicators.config_utils import get_indicator_dropdown_options, generate_parameter_fields_config, load_indicator_templates
def create_dynamic_parameter_fields(indicator_type: str) -> html.Div:
@@ -137,12 +137,8 @@ def create_indicator_modal():
children=[html.P("Select an indicator type to configure parameters", className="text-muted fst-italic")]
),
# Parameter fields (SMA, EMA, etc.)
create_dynamic_parameter_fields('sma'),
create_dynamic_parameter_fields('ema'),
create_dynamic_parameter_fields('rsi'),
create_dynamic_parameter_fields('macd'),
create_dynamic_parameter_fields('bollinger_bands'),
# Dynamically generate parameter fields for all indicator types
*[create_dynamic_parameter_fields(indicator_type) for indicator_type in load_indicator_templates().keys()],
html.Hr(),
# Styling Section