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'])
def recalculate_pivots():
"""Recalculate pivot points for merged data"""
"""Recalculate pivot points for merged data using cached data from data_loader"""
try:
data = request.get_json()
symbol = data.get('symbol', 'ETH/USDT')
timeframe = data.get('timeframe')
timestamps = data.get('timestamps', [])
ohlcv_data = data.get('ohlcv', {})
# We don't use timestamps/ohlcv from frontend anymore, we use our own consistent data source
if not timeframe or not timestamps:
if not timeframe:
return jsonify({
'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
df = pd.DataFrame({
'open': ohlcv_data.get('open', []),
'high': ohlcv_data.get('high', []),
'low': ohlcv_data.get('low', []),
'close': ohlcv_data.get('close', []),
'volume': ohlcv_data.get('volume', [])
})
df.index = pd.to_datetime(timestamps)
if not self.data_loader:
return jsonify({
'success': False,
'error': {'code': 'DATA_LOADER_UNAVAILABLE', 'message': 'Data loader not available'}
})
# 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 = 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
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:
logger.info(f" {timeframe}: {len(df)} candles ({df.index[0]} to {df.index[-1]})")
# Get pivot points for this timeframe
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df)
# Get pivot points for this timeframe (only if we have enough context)
pivot_markers = {}
if len(df) >= 50:
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df)
# Convert to format suitable for Plotly
chart_data[timeframe] = {