5.4 KiB
5.4 KiB
Architecture Refactoring - Phase 1 Completed
What Was Accomplished
1. Moved Core Data Models ✅
- InferenceFrameReference moved from
ANNOTATE/core/inference_training_system.pytocore/data_models.py - TrainingSession moved from
ANNOTATE/core/real_training_adapter.pytocore/data_models.py - Unified data models in single location for consistency
2. Integrated Training Coordination ✅
- Removed dependency on
ANNOTATE/core/inference_training_system.pyin orchestrator - Added integrated training coordination methods directly to
TradingOrchestrator:subscribe_training_events()- Subscribe to training eventsstore_inference_frame()- Store inference frames for trainingtrigger_training_on_event()- Trigger training based on eventsstart_training_session()/complete_training_session()- Manage training sessionsget_inference_frame()/update_inference_frame_results()- Manage inference frames
3. Extended Main DataProvider ✅
- Added annotation-specific methods to main
DataProvider:get_data_for_annotation()- Unified data access for annotation UIget_multi_timeframe_data_for_annotation()- Multi-timeframe data loadingdisable_startup_mode()- Compatibility method for annotation UI
- These methods combine functionality from the old
HistoricalDataLoader
4. Updated ANNOTATE App ✅
- Removed dependency on
ANNOTATE/core/data_loader.py - Updated all
data_loadercalls to usedata_provider.get_data_for_annotation() - Maintained backward compatibility while using unified data source
Architecture Improvements
Before (Problematic)
ANNOTATE/core/data_loader.py ──┐
├─ Duplicate data loading logic
core/data_provider.py ─────────┘
ANNOTATE/core/inference_training_system.py ──┐
├─ Duplicate training coordination
core/orchestrator.py ────────────────────────┘
Multiple data models scattered across both cores
After (Clean)
core/data_provider.py ──── Single data source with annotation support
core/orchestrator.py ───── Single training coordinator with integrated methods
core/data_models.py ───── Unified data models
ANNOTATE/web/app.py ───── Pure UI, uses main core classes
Live Data Flow Fixed
Root Cause Identified
The live data issue wasn't just client-side JavaScript errors. The fundamental problem was architectural duplication:
- WebSocket Integration: COB WebSocket was updating
core/data_provider.pyreal-time data - Data Isolation:
ANNOTATE/core/data_loader.pywas using cached data, not real-time data - API Calls: Live-updates API was calling the isolated data_loader, getting stale data
Solution Implemented
- Unified Data Source: ANNOTATE now uses main
DataProviderdirectly - Real-Time Integration:
get_data_for_annotation()usesget_latest_candles()which combines cached + real-time data - Live Update Detection: Small limit requests trigger real-time data access
- Fallback Mechanism: API refresh when WebSocket data unavailable
Expected Results
Live Updates Should Now Work Because:
- Single Data Pipeline: WebSocket → DataProvider → API → Charts (no duplication)
- Real-Time Integration: Live updates access the same data source that WebSocket updates
- Proper Detection: Live update requests are detected and routed to real-time data
- Server Timestamp: API responses include server time to verify freshness
Architecture Benefits:
- Single Source of Truth: One DataProvider, one Orchestrator, one set of data models
- No Duplication: Eliminated duplicate implementations and conflicting logic
- Cleaner Dependencies: ANNOTATE imports from main core, not vice versa
- Easier Maintenance: Single place to fix issues, consistent behavior
Next Steps (Future Phases)
Phase 2: Complete Cleanup
- Delete ANNOTATE/core/data_loader.py (no longer used)
- Move remaining ANNOTATE/core classes to main core if needed
- Remove ANNOTATE/core directory entirely
Phase 3: Test and Validate
- Test live updates work with unified architecture
- Verify training coordination works with integrated methods
- Confirm no regressions in existing functionality
Files Modified
Core System:
core/data_models.py- Added InferenceFrameReference and TrainingSessioncore/orchestrator.py- Added integrated training coordination methodscore/data_provider.py- Added annotation support methods
ANNOTATE App:
ANNOTATE/web/app.py- Updated to use main DataProvider instead of data_loader
Documentation:
- Created comprehensive refactoring documentation
- Documented architecture improvements and expected benefits
Impact on Live Updates
This refactoring should resolve the live updates issue because:
- Eliminated Data Isolation: No more separate data_loader with stale cached data
- Unified Real-Time Pipeline: WebSocket updates and API calls use same DataProvider
- Proper Live Detection: Small limit requests trigger real-time data access
- Combined Data Sources:
get_latest_candles()merges cached + real-time data
The combination of client-side JavaScript fixes + this backend architecture refactoring should provide a complete solution to the live updates problem.