Problem
The current MT5 data feed implementation in backend/data_server.py has known thread-safety issues. MT5's Python API is not thread-safe and must be accessed from the same thread it was initialized on. Under concurrent load, this can cause crashes or data inconsistencies.
Current Behavior
- MT5 calls are made from multiple threads without proper synchronization
- Intermittent crashes or disconnections under heavy load
- No dedicated MT5 thread or queue-based communication pattern
Expected Behavior
- MT5 interactions should be isolated to a single dedicated thread
- A thread-safe queue or event loop pattern should handle requests/responses
- The fix should not introduce latency in the data feed
Suggested Approach
- Create a dedicated
MT5Thread class that owns the MT5 connection
- Use
queue.Queue for inter-thread communication
- Replace direct MT5 calls from async handlers with queue-based requests
Files Involved
backend/data_server.py
backend/providers/ (MT5 provider)
Skills Needed
Python, Threading, asyncio, MetaTrader5 API
Problem
The current MT5 data feed implementation in
backend/data_server.pyhas known thread-safety issues. MT5's Python API is not thread-safe and must be accessed from the same thread it was initialized on. Under concurrent load, this can cause crashes or data inconsistencies.Current Behavior
Expected Behavior
Suggested Approach
MT5Threadclass that owns the MT5 connectionqueue.Queuefor inter-thread communicationFiles Involved
backend/data_server.pybackend/providers/(MT5 provider)Skills Needed
Python, Threading, asyncio, MetaTrader5 API