more detailed messages
This commit is contained in:
@ -545,12 +545,16 @@
|
|||||||
ws.onmessage = function(event) {
|
ws.onmessage = function(event) {
|
||||||
try {
|
try {
|
||||||
const data = JSON.parse(event.data);
|
const data = JSON.parse(event.data);
|
||||||
|
console.log(`🔌 WebSocket message received:`, data.type, data.symbol || 'no symbol');
|
||||||
|
|
||||||
if (data.type === 'cob_update') {
|
if (data.type === 'cob_update') {
|
||||||
handleCOBUpdate(data);
|
handleCOBUpdate(data);
|
||||||
|
} else {
|
||||||
|
console.log(`🔌 Unhandled WebSocket message type:`, data.type);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error parsing WebSocket message:', error);
|
console.error('❌ Error parsing WebSocket message:', error);
|
||||||
|
console.error('Raw message:', event.data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -580,7 +584,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Debug logging to understand data structure
|
// Debug logging to understand data structure
|
||||||
console.log(`${symbol} COB Update:`, {
|
console.log(`🔄 ${symbol} COB Update:`, {
|
||||||
|
source: data.type || 'Unknown',
|
||||||
bidsCount: (cobData.bids || []).length,
|
bidsCount: (cobData.bids || []).length,
|
||||||
asksCount: (cobData.asks || []).length,
|
asksCount: (cobData.asks || []).length,
|
||||||
sampleBid: (cobData.bids || [])[0],
|
sampleBid: (cobData.bids || [])[0],
|
||||||
@ -588,7 +593,8 @@
|
|||||||
stats: cobData.stats,
|
stats: cobData.stats,
|
||||||
hasOHLCV: !!cobData.ohlcv,
|
hasOHLCV: !!cobData.ohlcv,
|
||||||
ohlcvCount: cobData.ohlcv ? cobData.ohlcv.length : 0,
|
ohlcvCount: cobData.ohlcv ? cobData.ohlcv.length : 0,
|
||||||
sampleOHLCV: cobData.ohlcv ? cobData.ohlcv[0] : null
|
sampleOHLCV: cobData.ohlcv ? cobData.ohlcv[0] : null,
|
||||||
|
ohlcvStructure: cobData.ohlcv ? Object.keys(cobData.ohlcv[0] || {}) : 'none'
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if WebSocket data has insufficient depth, fetch REST data
|
// Check if WebSocket data has insufficient depth, fetch REST data
|
||||||
@ -596,7 +602,7 @@
|
|||||||
const asks = cobData.asks || [];
|
const asks = cobData.asks || [];
|
||||||
|
|
||||||
if (bids.length <= 1 && asks.length <= 1) {
|
if (bids.length <= 1 && asks.length <= 1) {
|
||||||
console.log(`Insufficient WS depth for ${symbol}, fetching REST data...`);
|
console.log(`⚠️ Insufficient WS depth for ${symbol}, fetching REST data...`);
|
||||||
fetchRESTData(symbol);
|
fetchRESTData(symbol);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -604,17 +610,31 @@
|
|||||||
currentData[symbol] = cobData;
|
currentData[symbol] = cobData;
|
||||||
|
|
||||||
// Process OHLCV data if available
|
// Process OHLCV data if available
|
||||||
if (cobData.ohlcv && Array.isArray(cobData.ohlcv)) {
|
if (cobData.ohlcv && Array.isArray(cobData.ohlcv) && cobData.ohlcv.length > 0) {
|
||||||
ohlcvData[symbol] = cobData.ohlcv;
|
ohlcvData[symbol] = cobData.ohlcv;
|
||||||
console.log(`${symbol} OHLCV data received:`, cobData.ohlcv.length, 'candles');
|
console.log(`📈 ${symbol} OHLCV data received:`, cobData.ohlcv.length, 'candles');
|
||||||
|
|
||||||
|
// Log first and last candle for debugging
|
||||||
|
const firstCandle = cobData.ohlcv[0];
|
||||||
|
const lastCandle = cobData.ohlcv[cobData.ohlcv.length - 1];
|
||||||
|
console.log(`📊 ${symbol} OHLCV range:`, {
|
||||||
|
first: firstCandle,
|
||||||
|
last: lastCandle,
|
||||||
|
priceRange: `${Math.min(...cobData.ohlcv.map(c => c.low))} - ${Math.max(...cobData.ohlcv.map(c => c.high))}`
|
||||||
|
});
|
||||||
|
|
||||||
// Update mini chart after order book update
|
// Update mini chart after order book update
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const prefix = symbol === 'BTC/USDT' ? 'btc' : 'eth';
|
const prefix = symbol === 'BTC/USDT' ? 'btc' : 'eth';
|
||||||
|
console.log(`🎨 Drawing chart for ${prefix} with ${cobData.ohlcv.length} candles`);
|
||||||
drawMiniChart(prefix, cobData.ohlcv);
|
drawMiniChart(prefix, cobData.ohlcv);
|
||||||
}, 100);
|
}, 100);
|
||||||
} else {
|
} else {
|
||||||
console.log(`${symbol}: No OHLCV data in update`);
|
console.log(`❌ ${symbol}: No valid OHLCV data in update (${cobData.ohlcv ? cobData.ohlcv.length : 'null'} items)`);
|
||||||
|
|
||||||
|
// Try to get OHLCV from REST endpoint
|
||||||
|
console.log(`🔍 Trying to fetch OHLCV from REST for ${symbol}...`);
|
||||||
|
fetchRESTData(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Track imbalance for aggregation
|
// Track imbalance for aggregation
|
||||||
@ -636,15 +656,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function fetchRESTData(symbol) {
|
function fetchRESTData(symbol) {
|
||||||
|
console.log(`🔍 Fetching REST data for ${symbol}...`);
|
||||||
fetch(`/api/cob/${encodeURIComponent(symbol)}`)
|
fetch(`/api/cob/${encodeURIComponent(symbol)}`)
|
||||||
.then(response => response.json())
|
.then(response => {
|
||||||
|
console.log(`📡 REST response for ${symbol}:`, response.status, response.statusText);
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
console.log(`📦 REST data received for ${symbol}:`, {
|
||||||
|
hasData: !!data.data,
|
||||||
|
dataKeys: data.data ? Object.keys(data.data) : [],
|
||||||
|
hasOHLCV: !!(data.data && data.data.ohlcv),
|
||||||
|
ohlcvCount: data.data && data.data.ohlcv ? data.data.ohlcv.length : 0
|
||||||
|
});
|
||||||
|
|
||||||
if (data.data) {
|
if (data.data) {
|
||||||
console.log(`REST fallback data for ${symbol}:`, data.data);
|
console.log(`✅ Processing REST fallback data for ${symbol}`);
|
||||||
handleCOBUpdate({symbol: symbol, data: data.data});
|
handleCOBUpdate({symbol: symbol, data: data.data, type: 'rest_api'});
|
||||||
|
} else {
|
||||||
|
console.error(`❌ No data in REST response for ${symbol}`);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => console.error(`Error fetching REST data for ${symbol}:`, error));
|
.catch(error => console.error(`❌ Error fetching REST data for ${symbol}:`, error));
|
||||||
}
|
}
|
||||||
|
|
||||||
function trackImbalance(symbol, imbalance) {
|
function trackImbalance(symbol, imbalance) {
|
||||||
@ -1028,7 +1061,7 @@
|
|||||||
try {
|
try {
|
||||||
const canvas = document.getElementById(`${prefix}-mini-chart`);
|
const canvas = document.getElementById(`${prefix}-mini-chart`);
|
||||||
if (!canvas) {
|
if (!canvas) {
|
||||||
console.log(`Canvas not found for ${prefix}-mini-chart`);
|
console.error(`❌ Canvas not found for ${prefix}-mini-chart`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1036,10 +1069,11 @@
|
|||||||
const width = canvas.width;
|
const width = canvas.width;
|
||||||
const height = canvas.height;
|
const height = canvas.height;
|
||||||
|
|
||||||
console.log(`Drawing ${prefix} chart with ${ohlcvArray ? ohlcvArray.length : 0} candles`);
|
console.log(`🎨 Drawing ${prefix} chart with ${ohlcvArray ? ohlcvArray.length : 0} candles (${width}x${height})`);
|
||||||
|
|
||||||
// Clear canvas
|
// Clear canvas with background
|
||||||
ctx.clearRect(0, 0, width, height);
|
ctx.fillStyle = '#111';
|
||||||
|
ctx.fillRect(0, 0, width, height);
|
||||||
|
|
||||||
if (!ohlcvArray || ohlcvArray.length === 0) {
|
if (!ohlcvArray || ohlcvArray.length === 0) {
|
||||||
// Draw "No Data" message
|
// Draw "No Data" message
|
||||||
@ -1047,7 +1081,18 @@
|
|||||||
ctx.font = '12px Courier New';
|
ctx.font = '12px Courier New';
|
||||||
ctx.textAlign = 'center';
|
ctx.textAlign = 'center';
|
||||||
ctx.fillText('No Data', width / 2, height / 2);
|
ctx.fillText('No Data', width / 2, height / 2);
|
||||||
console.log(`${prefix}: No OHLCV data to draw`);
|
console.log(`❌ ${prefix}: No OHLCV data to draw`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate OHLCV data structure
|
||||||
|
const firstCandle = ohlcvArray[0];
|
||||||
|
if (!firstCandle || typeof firstCandle.open === 'undefined' || typeof firstCandle.close === 'undefined') {
|
||||||
|
console.error(`❌ ${prefix}: Invalid OHLCV data structure:`, firstCandle);
|
||||||
|
ctx.fillStyle = '#ff6b6b';
|
||||||
|
ctx.font = '10px Courier New';
|
||||||
|
ctx.textAlign = 'center';
|
||||||
|
ctx.fillText('Invalid Data', width / 2, height / 2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1061,7 +1106,16 @@
|
|||||||
const maxPrice = Math.max(...prices);
|
const maxPrice = Math.max(...prices);
|
||||||
const priceRange = maxPrice - minPrice;
|
const priceRange = maxPrice - minPrice;
|
||||||
|
|
||||||
if (priceRange === 0) return;
|
console.log(`📊 ${prefix} price range: $${minPrice.toFixed(2)} - $${maxPrice.toFixed(2)} (range: $${priceRange.toFixed(2)})`);
|
||||||
|
|
||||||
|
if (priceRange === 0) {
|
||||||
|
console.warn(`⚠️ ${prefix}: Zero price range, cannot draw chart`);
|
||||||
|
ctx.fillStyle = '#ff6b6b';
|
||||||
|
ctx.font = '10px Courier New';
|
||||||
|
ctx.textAlign = 'center';
|
||||||
|
ctx.fillText('Zero Range', width / 2, height / 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate candle width and spacing
|
// Calculate candle width and spacing
|
||||||
const candleWidth = Math.max(1, Math.floor(width / ohlcvArray.length) - 1);
|
const candleWidth = Math.max(1, Math.floor(width / ohlcvArray.length) - 1);
|
||||||
@ -1124,8 +1178,11 @@
|
|||||||
ctx.setLineDash([]);
|
ctx.setLineDash([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`✅ Successfully drew ${prefix} chart with ${ohlcvArray.length} candles`);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error drawing mini chart for ${prefix}:`, error);
|
console.error(`❌ Error drawing mini chart for ${prefix}:`, error);
|
||||||
|
console.error(error.stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,7 +194,11 @@ class COBDashboardServer:
|
|||||||
|
|
||||||
# Get latest data from cache or COB integration
|
# Get latest data from cache or COB integration
|
||||||
if symbol in self.latest_cob_data:
|
if symbol in self.latest_cob_data:
|
||||||
data = self.latest_cob_data[symbol]
|
data = self.latest_cob_data[symbol].copy()
|
||||||
|
# Add OHLCV data to REST response
|
||||||
|
if symbol in self.ohlcv_data:
|
||||||
|
data['ohlcv'] = list(self.ohlcv_data[symbol])
|
||||||
|
logger.debug(f"REST API: Added {len(data['ohlcv'])} OHLCV candles for {symbol}")
|
||||||
elif self.cob_integration:
|
elif self.cob_integration:
|
||||||
data = await self._generate_dashboard_data(symbol)
|
data = await self._generate_dashboard_data(symbol)
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user