T live WIP
This commit is contained in:
@@ -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 = 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': {}
|
||||||
})
|
})
|
||||||
df.index = pd.to_datetime(timestamps)
|
|
||||||
|
|
||||||
# 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,7 +1158,9 @@ 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 = {}
|
||||||
|
if len(df) >= 50:
|
||||||
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df)
|
pivot_markers = self._get_pivot_markers_for_timeframe(symbol, timeframe, df)
|
||||||
|
|
||||||
# Convert to format suitable for Plotly
|
# Convert to format suitable for Plotly
|
||||||
|
|||||||
@@ -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
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user