T live WIP

This commit is contained in:
Dobromir Popov
2025-11-22 01:31:42 +02:00
parent a1d3d6a865
commit 21813fbfe3
2 changed files with 35 additions and 26 deletions

View File

@@ -1054,31 +1054,42 @@ class AnnotationDashboard:
@self.server.route('/api/recalculate-pivots', methods=['POST']) @self.server.route('/api/recalculate-pivots', methods=['POST'])
def recalculate_pivots(): def recalculate_pivots():
"""Recalculate pivot points for merged data""" """Recalculate pivot points for merged data using cached data from data_loader"""
try: try:
data = request.get_json() data = request.get_json()
symbol = data.get('symbol', 'ETH/USDT') symbol = data.get('symbol', 'ETH/USDT')
timeframe = data.get('timeframe') timeframe = data.get('timeframe')
timestamps = data.get('timestamps', []) # We don't use timestamps/ohlcv from frontend anymore, we use our own consistent data source
ohlcv_data = data.get('ohlcv', {})
if not timeframe or not timestamps: if not timeframe:
return jsonify({ return jsonify({
'success': False, 'success': False,
'error': {'code': 'INVALID_REQUEST', 'message': 'Missing timeframe or timestamps'} 'error': {'code': 'INVALID_REQUEST', 'message': 'Missing timeframe'}
}) })
logger.info(f" Recalculating pivots for {symbol} {timeframe} with {len(timestamps)} candles") logger.info(f" Recalculating pivots for {symbol} {timeframe} using backend data")
# Convert to DataFrame if not self.data_loader:
df = pd.DataFrame({ return jsonify({
'open': ohlcv_data.get('open', []), 'success': False,
'high': ohlcv_data.get('high', []), 'error': {'code': 'DATA_LOADER_UNAVAILABLE', 'message': 'Data loader not available'}
'low': ohlcv_data.get('low', []), })
'close': ohlcv_data.get('close', []),
'volume': ohlcv_data.get('volume', []) # Fetch latest data from data_loader (which should have the updated cache/DB from previous calls)
}) # We get enough history for proper pivot calculation
df.index = pd.to_datetime(timestamps) df = self.data_loader.get_data(
symbol=symbol,
timeframe=timeframe,
limit=2500, # Enough for context
direction='latest'
)
if df is None or df.empty:
logger.warning(f"No data found for {symbol} {timeframe} to recalculate pivots")
return jsonify({
'success': True,
'pivot_markers': {}
})
# Recalculate pivot markers # Recalculate pivot markers
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df) pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df)
@@ -1147,8 +1158,10 @@ class AnnotationDashboard:
if df is not None and not df.empty: if df is not None and not df.empty:
logger.info(f" {timeframe}: {len(df)} candles ({df.index[0]} to {df.index[-1]})") logger.info(f" {timeframe}: {len(df)} candles ({df.index[0]} to {df.index[-1]})")
# Get pivot points for this timeframe # Get pivot points for this timeframe (only if we have enough context)
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df) pivot_markers = {}
if len(df) >= 50:
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df)
# Convert to format suitable for Plotly # Convert to format suitable for Plotly
chart_data[timeframe] = { chart_data[timeframe] = {

View File

@@ -1616,22 +1616,18 @@ class ChartManager {
*/ */
async recalculatePivots(timeframe, data) { async recalculatePivots(timeframe, data) {
try { try {
// Don't recalculate if we don't have enough data
if (data.timestamps.length < 50) return;
console.log(` Recalculating pivots for ${timeframe} with ${data.timestamps.length} candles...`); console.log(` Recalculating pivots for ${timeframe} with ${data.timestamps.length} candles...`);
// Optimized: Only send symbol and timeframe, backend uses its own data
const response = await fetch('/api/recalculate-pivots', { const response = await fetch('/api/recalculate-pivots', {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ body: JSON.stringify({
symbol: window.appState?.currentSymbol || 'ETH/USDT', symbol: window.appState?.currentSymbol || 'ETH/USDT',
timeframe: timeframe, timeframe: timeframe
timestamps: data.timestamps,
ohlcv: {
open: data.open,
high: data.high,
low: data.low,
close: data.close,
volume: data.volume
}
}) })
}); });