diff --git a/core/cob_integration.py b/core/cob_integration.py index b0ef2df..47c38fa 100644 --- a/core/cob_integration.py +++ b/core/cob_integration.py @@ -313,39 +313,28 @@ class COBIntegration: bucket_price = math.floor(ask.price / bucket_size) * bucket_size ask_buckets[bucket_price] += ask.total_volume_usd - # Convert to sorted arrays for visualization + # Convert directly from consolidated order book levels bid_data = [] ask_data = [] - # Generate price levels - min_price = math.floor((mid_price - (price_range * bucket_size)) / bucket_size) * bucket_size - max_price = math.ceil((mid_price + (price_range * bucket_size)) / bucket_size) * bucket_size + # Use actual order book data instead of bucketed data for better precision + for i, bid in enumerate(cob_snapshot.consolidated_bids[:100]): # Increased from 25 to 100 bid levels + bid_data.append({ + 'price': bid.price, + 'volume': bid.total_volume_usd, + 'side': 'bid' + }) - # Fill bid data - current_price = mid_price - while current_price >= min_price: - bucket_price = math.floor(current_price / bucket_size) * bucket_size - volume = bid_buckets.get(bucket_price, 0) - if volume > 0: - bid_data.append({ - 'price': bucket_price, - 'volume': volume, - 'side': 'bid' - }) - current_price -= bucket_size + for i, ask in enumerate(cob_snapshot.consolidated_asks[:100]): # Increased from 25 to 100 ask levels + ask_data.append({ + 'price': ask.price, + 'volume': ask.total_volume_usd, + 'side': 'ask' + }) - # Fill ask data - current_price = mid_price - while current_price <= max_price: - bucket_price = math.floor(current_price / bucket_size) * bucket_size - volume = ask_buckets.get(bucket_price, 0) - if volume > 0: - ask_data.append({ - 'price': bucket_price, - 'volume': volume, - 'side': 'ask' - }) - current_price += bucket_size + logger.debug(f"Dashboard data for {symbol}: {len(bid_data)} bids, {len(ask_data)} asks") + logger.debug(f"Top bid: ${bid_data[0]['price']:.2f} (${bid_data[0]['volume']:,.0f})" if bid_data else "No bids") + logger.debug(f"Top ask: ${ask_data[0]['price']:.2f} (${ask_data[0]['volume']:,.0f})" if ask_data else "No asks") # Get actual Session Volume Profile (SVP) from trade data svp_data = [] @@ -365,9 +354,14 @@ class COBIntegration: 'timestamp': cob_snapshot.timestamp.isoformat(), 'mid_price': cob_snapshot.volume_weighted_mid, 'spread_bps': cob_snapshot.spread_bps, + 'bid_liquidity': cob_snapshot.total_bid_liquidity, + 'ask_liquidity': cob_snapshot.total_ask_liquidity, 'total_bid_liquidity': cob_snapshot.total_bid_liquidity, 'total_ask_liquidity': cob_snapshot.total_ask_liquidity, + 'imbalance': cob_snapshot.liquidity_imbalance, 'liquidity_imbalance': cob_snapshot.liquidity_imbalance, + 'bid_levels': len(bid_data), + 'ask_levels': len(ask_data), 'exchanges_active': cob_snapshot.exchanges_active, 'bucket_size': bucket_size } diff --git a/core/multi_exchange_cob_provider.py b/core/multi_exchange_cob_provider.py index beaa622..d3dd2c7 100644 --- a/core/multi_exchange_cob_provider.py +++ b/core/multi_exchange_cob_provider.py @@ -120,8 +120,8 @@ class MultiExchangeCOBProvider: self.consolidation_frequency = 100 # ms # REST API configuration for deep order book - self.rest_api_frequency = 5000 # ms - full snapshot every 5 seconds - self.rest_depth_limit = 1000 # Get up to 1000 levels via REST + self.rest_api_frequency = 1000 # ms - full snapshot every 1 second + self.rest_depth_limit = 500 # Increased from 100 to 500 levels via REST for maximum depth # Exchange configurations self.exchange_configs = self._initialize_exchange_configs() @@ -158,7 +158,7 @@ class MultiExchangeCOBProvider: self.session_trades: Dict[str, List[Dict]] = {symbol: [] for symbol in self.symbols} self.svp_cache: Dict[str, Dict] = {symbol: {} for symbol in self.symbols} - # Fixed USD bucket sizes for different symbols + # Fixed USD bucket sizes for different symbols as requested self.fixed_usd_buckets = { 'BTC/USDT': 10.0, # $10 buckets for BTC 'ETH/USDT': 1.0, # $1 buckets for ETH @@ -870,12 +870,12 @@ class MultiExchangeCOBProvider: # Generate fine-grain price buckets price_buckets = self._generate_price_buckets(symbol, sorted_bids, sorted_asks, volume_weighted_mid) - # Create consolidated snapshot + # Create consolidated snapshot with more levels for dashboard cob_snapshot = COBSnapshot( symbol=symbol, timestamp=timestamp, - consolidated_bids=sorted_bids[:50], # Top 50 levels - consolidated_asks=sorted_asks[:50], + consolidated_bids=sorted_bids[:100], # Top 100 levels for better dashboard display + consolidated_asks=sorted_asks[:100], exchanges_active=active_exchanges, volume_weighted_mid=volume_weighted_mid, total_bid_liquidity=total_bid_liquidity, diff --git a/web/cob_dashboard.html b/web/cob_dashboard.html index 867c99a..a885bb2 100644 --- a/web/cob_dashboard.html +++ b/web/cob_dashboard.html @@ -3,11 +3,10 @@
-