- Enhanced the `UserIndicator` class to include an optional `timeframe` attribute for custom indicator timeframes. - Updated the `get_indicator_data` method in `MarketDataIntegrator` to fetch and calculate indicators based on the specified timeframe, ensuring proper data alignment and handling. - Modified the `ChartBuilder` to pass the correct DataFrame for plotting indicators with different timeframes. - Added UI elements in the indicator modal for selecting timeframes, improving user experience. - Updated relevant JSON templates to include the new `timeframe` field for all indicators. - Refactored the `prepare_chart_data` function to ensure it returns a DataFrame with a `DatetimeIndex` for consistent calculations. This commit enhances the flexibility and usability of the indicator system, allowing users to analyze data across various timeframes.
3.1 KiB
3.1 KiB
Relevant Files
data/common/indicators.py- This is the primary file to be refactored. TheTechnicalIndicatorsclass will be modified to be DataFrame-centric.components/charts/utils.py- Theprepare_chart_datafunction in this file needs to be corrected to ensure it properly creates and returns a DataFrame with aDatetimeIndex.components/charts/data_integration.py- This file'sget_indicator_datamethod will be simplified to pass the correctly prepared DataFrame to the calculation engine.app_new.py- The main application file, which will be used to run the dashboard and perform end-to-end testing.
Notes
- The goal of this refactoring is to create a more robust and maintainable data pipeline for indicator calculations, preventing recurring data type and index errors.
- Pay close attention to ensuring that DataFrames have a consistent
DatetimeIndexwith proper timezone information throughout the pipeline.
Tasks
-
1.0 Refactor
TechnicalIndicatorsClass indata/common/indicators.pyto be DataFrame-centric.- 1.1 Modify
sma,ema,rsi,macd, andbollinger_bandsmethods to accept a pre-formatted DataFrame as their primary input, not a list of candles. - 1.2 Remove the redundant
prepare_dataframecall from within each individual indicator method. - 1.3 Rename
prepare_dataframeto_prepare_dataframe_from_listto signify its new role as a private helper for converting list-based data. - 1.4 Update the main
calculatemethod to be the single point of data preparation, handling both DataFrame and list inputs.
- 1.1 Modify
-
2.0 Correct DataFrame Preparation in
components/charts/utils.py.- 2.1 Review the
prepare_chart_datafunction to identify why theDatetimeIndexis being dropped. - 2.2 Modify the function to ensure it returns a DataFrame with the
timestampcolumn correctly set as the index, without areset_index()call at the end.
- 2.1 Review the
-
3.0 Simplify Data Flow in
components/charts/data_integration.py.- 3.1 In the
get_indicator_datafunction, remove the workaround that converts the DataFrame to a list of dictionaries (to_dict('records')). - 3.2 Ensure the function correctly handles both main and custom timeframes, passing the appropriate DataFrame to the calculation engine.
- 3.3 Verify that the final
reindexoperation works correctly with the consistent DataFrame structure.
- 3.1 In the
-
4.0 End-to-End Testing and Validation.
- 4.1 Run the dashboard and test the indicator plotting functionality with both matching and custom timeframes.
- 4.2 Verify that no new errors appear in the console during chart interaction.
-
5.0 Update Indicators documentation to reflect the new DataFrame-centric approach.
- 5.1 Review the documentation in the
/docsdirectory related to indicators. - 5.2 Update the documentation to explain that the calculation engine now uses DataFrames.
- 5.3 Provide clear examples of how to use the refactored
TechnicalIndicatorsclass.
- 5.1 Review the documentation in the