try to fix live RT updates on ANNOTATE

This commit is contained in:
Dobromir Popov
2025-11-22 00:55:37 +02:00
parent feb6cec275
commit a7def3b788
5 changed files with 328 additions and 57 deletions

View File

@@ -224,6 +224,7 @@ class BacktestRunner:
if orchestrator and hasattr(orchestrator, 'store_transformer_prediction'):
# Determine model type from model class name
model_type = model.__class__.__name__.lower()
logger.debug(f"Backtest: Storing prediction for model type: {model_type}")
# Store in appropriate prediction collection
if 'transformer' in model_type:
@@ -236,6 +237,7 @@ class BacktestRunner:
'action': prediction['action'],
'horizon_minutes': 10
})
logger.debug(f"Backtest: Stored transformer prediction: {prediction['action']} @ {current_price}")
elif 'cnn' in model_type:
if hasattr(orchestrator, 'recent_cnn_predictions'):
if symbol not in orchestrator.recent_cnn_predictions:
@@ -2006,12 +2008,14 @@ class AnnotationDashboard:
@self.server.route('/api/realtime-inference/start', methods=['POST'])
def start_realtime_inference():
"""Start real-time inference mode with optional live training on L2 pivots"""
"""Start real-time inference mode with optional training modes"""
try:
data = request.get_json()
model_name = data.get('model_name')
symbol = data.get('symbol', 'ETH/USDT')
enable_live_training = data.get('enable_live_training', True) # Default: enabled
timeframe = data.get('timeframe', '1m')
enable_live_training = data.get('enable_live_training', False) # Pivot-based training
train_every_candle = data.get('train_every_candle', False) # Per-candle training
if not self.training_adapter:
return jsonify({
@@ -2022,18 +2026,23 @@ class AnnotationDashboard:
}
})
# Start real-time inference with optional live training
# Start real-time inference with optional training modes
inference_id = self.training_adapter.start_realtime_inference(
model_name=model_name,
symbol=symbol,
data_provider=self.data_provider,
enable_live_training=enable_live_training
enable_live_training=enable_live_training,
train_every_candle=train_every_candle,
timeframe=timeframe
)
training_mode = "per-candle" if train_every_candle else ("pivot-based" if enable_live_training else "inference-only")
return jsonify({
'success': True,
'inference_id': inference_id,
'live_training_enabled': enable_live_training
'training_mode': training_mode,
'timeframe': timeframe
})
except Exception as e:

View File

@@ -80,7 +80,15 @@
<button class="btn btn-success btn-sm w-100" id="start-inference-btn">
<i class="fas fa-play"></i>
Start Live Inference
Start Live Inference (No Training)
</button>
<button class="btn btn-info btn-sm w-100 mt-1" id="start-inference-pivot-btn">
<i class="fas fa-chart-line"></i>
Live Inference + Pivot Training
</button>
<button class="btn btn-primary btn-sm w-100 mt-1" id="start-inference-candle-btn">
<i class="fas fa-graduation-cap"></i>
Live Inference + Per-Candle Training
</button>
<button class="btn btn-danger btn-sm w-100 mt-1" id="stop-inference-btn" style="display: none;">
<i class="fas fa-stop"></i>
@@ -511,7 +519,8 @@
document.getElementById('active-steps').textContent = steps;
});
document.getElementById('start-inference-btn').addEventListener('click', function () {
// Helper function to start inference with different modes
function startInference(enableLiveTraining, trainEveryCandle) {
const modelName = document.getElementById('model-select').value;
if (!modelName) {
@@ -519,9 +528,8 @@
return;
}
// Get primary timeframe and prediction steps
const primaryTimeframe = document.getElementById('primary-timeframe-select').value;
const predictionSteps = parseInt(document.getElementById('prediction-steps-slider').value);
// Get timeframe
const timeframe = document.getElementById('primary-timeframe-select').value;
// Start real-time inference
fetch('/api/realtime-inference/start', {
@@ -530,8 +538,9 @@
body: JSON.stringify({
model_name: modelName,
symbol: appState.currentSymbol,
primary_timeframe: primaryTimeframe,
prediction_steps: predictionSteps
timeframe: timeframe,
enable_live_training: enableLiveTraining,
train_every_candle: trainEveryCandle
})
})
.then(response => response.json())
@@ -541,6 +550,8 @@
// Update UI
document.getElementById('start-inference-btn').style.display = 'none';
document.getElementById('start-inference-pivot-btn').style.display = 'none';
document.getElementById('start-inference-candle-btn').style.display = 'none';
document.getElementById('stop-inference-btn').style.display = 'block';
document.getElementById('inference-status').style.display = 'block';
document.getElementById('inference-controls').style.display = 'block';
@@ -558,7 +569,10 @@
// Start polling for signals
startSignalPolling();
showSuccess('Real-time inference started - Charts now updating live');
const trainingMode = data.training_mode || 'inference-only';
const modeText = trainingMode === 'per-candle' ? ' with per-candle training' :
(trainingMode === 'pivot-based' ? ' with pivot training' : '');
showSuccess('Real-time inference started' + modeText);
} else {
showError('Failed to start inference: ' + data.error.message);
}
@@ -566,6 +580,19 @@
.catch(error => {
showError('Network error: ' + error.message);
});
}
// Button handlers for different inference modes
document.getElementById('start-inference-btn').addEventListener('click', function () {
startInference(false, false); // No training
});
document.getElementById('start-inference-pivot-btn').addEventListener('click', function () {
startInference(true, false); // Pivot-based training
});
document.getElementById('start-inference-candle-btn').addEventListener('click', function () {
startInference(false, true); // Per-candle training
});
document.getElementById('stop-inference-btn').addEventListener('click', function () {
@@ -582,6 +609,8 @@
if (data.success) {
// Update UI
document.getElementById('start-inference-btn').style.display = 'block';
document.getElementById('start-inference-pivot-btn').style.display = 'block';
document.getElementById('start-inference-candle-btn').style.display = 'block';
document.getElementById('stop-inference-btn').style.display = 'none';
document.getElementById('inference-status').style.display = 'none';
document.getElementById('inference-controls').style.display = 'none';