This commit is contained in:
Dobromir Popov
2025-10-23 19:43:41 +03:00
parent 0225f4df58
commit de2ad92602
5 changed files with 379 additions and 96 deletions

View File

@@ -61,8 +61,8 @@
// Initialize application state
window.appState = {
currentSymbol: '{{ current_symbol }}',
currentTimeframes: {{ timeframes | tojson }},
annotations: { { annotations | tojson } },
currentTimeframes: '{{ timeframes | tojson }}',
annotations: '{{ annotations | tojson }}',
pendingAnnotation: null,
chartManager: null,
annotationManager: null,
@@ -95,7 +95,87 @@
});
function loadInitialData() {
console.log('Loading initial chart data...');
// Fetch initial chart data
fetch('/api/chart-data', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
symbol: appState.currentSymbol,
timeframes: appState.currentTimeframes,
start_time: null,
end_time: null
})
})
.then(response => {
console.log('Chart data response status:', response.status);
return response.json();
})
.then(data => {
console.log('Chart data received:', data);
if (data.success) {
console.log('Initializing charts with data...');
window.appState.chartManager.initializeCharts(data.chart_data, data.pivot_bounds);
// Show pivot bounds info if available
if (data.pivot_bounds) {
const pivotInfo = data.pivot_bounds;
console.log(`Loaded ${pivotInfo.total_levels} pivot levels (${pivotInfo.support_levels.length} support, ${pivotInfo.resistance_levels.length} resistance) from ${pivotInfo.timeframe} data over ${pivotInfo.period}`);
}
// Load existing annotations
console.log('Loading', window.appState.annotations.length, 'existing annotations');
window.appState.annotations.forEach(annotation => {
window.appState.chartManager.addAnnotation(annotation);
});
// Update annotation list
if (typeof renderAnnotationsList === 'function') {
renderAnnotationsList(window.appState.annotations);
}
// DISABLED: Live updates were causing data corruption (red wall issue)
// Use manual refresh button instead
// startLiveChartUpdates();
console.log('Initial data load complete');
} else {
console.error('Chart data load failed:', data.error);
showError('Failed to load chart data: ' + data.error.message);
}
})
.catch(error => {
console.error('Chart data fetch error:', error);
showError('Network error: ' + error.message);
});
}
// Live chart update mechanism
let liveUpdateInterval = null;
function startLiveChartUpdates() {
// Clear any existing interval
if (liveUpdateInterval) {
clearInterval(liveUpdateInterval);
}
console.log('Starting live chart updates (1s interval)');
// Update every second for 1s chart
liveUpdateInterval = setInterval(() => {
updateLiveChartData();
}, 1000);
}
function updateLiveChartData() {
// Only update if we have a chart manager
if (!window.appState || !window.appState.chartManager) {
return;
}
// Fetch latest data
fetch('/api/chart-data', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
@@ -108,28 +188,30 @@
})
.then(response => response.json())
.then(data => {
if (data.success) {
window.appState.chartManager.initializeCharts(data.chart_data);
if (data.success && window.appState.chartManager) {
// Update charts with new data and pivot bounds
window.appState.chartManager.updateCharts(data.chart_data, data.pivot_bounds);
// Load existing annotations
console.log('Loading', window.appState.annotations.length, 'existing annotations');
window.appState.annotations.forEach(annotation => {
window.appState.chartManager.addAnnotation(annotation);
});
// Update annotation list
if (typeof renderAnnotationsList === 'function') {
renderAnnotationsList(window.appState.annotations);
// Show pivot bounds info if available
if (data.pivot_bounds) {
const pivotInfo = data.pivot_bounds;
console.log(`Loaded ${pivotInfo.total_levels} pivot levels (${pivotInfo.support_levels.length} support, ${pivotInfo.resistance_levels.length} resistance) from ${pivotInfo.timeframe} data over ${pivotInfo.period}`);
}
} else {
showError('Failed to load chart data: ' + data.error.message);
}
})
.catch(error => {
showError('Network error: ' + error.message);
console.debug('Live update error:', error);
// Don't show error to user for live updates
});
}
// Clean up on page unload
window.addEventListener('beforeunload', function () {
if (liveUpdateInterval) {
clearInterval(liveUpdateInterval);
}
});
function setupKeyboardShortcuts() {
document.addEventListener('keydown', function (e) {
// Arrow left - navigate backward

View File

@@ -218,11 +218,18 @@
.then(response => response.json())
.then(data => {
if (data.success) {
// Update charts with new data
// Update charts with new data and pivot bounds
if (appState.chartManager) {
appState.chartManager.updateCharts(data.chart_data);
appState.chartManager.updateCharts(data.chart_data, data.pivot_bounds);
}
// Show pivot bounds info if available
if (data.pivot_bounds) {
const pivotInfo = data.pivot_bounds;
showSuccess(`Chart data refreshed successfully. Found ${pivotInfo.total_levels} pivot levels (${pivotInfo.support_levels.length} support, ${pivotInfo.resistance_levels.length} resistance) from ${pivotInfo.timeframe} data over ${pivotInfo.period}`);
} else {
showSuccess('Chart data refreshed successfully');
}
showSuccess('Chart data refreshed successfully');
} else {
showError('Failed to refresh data: ' + data.error.message);
}