From d902e01197c9ddcacb28ee6ba7a67c1ef8d705bf Mon Sep 17 00:00:00 2001 From: Dobromir Popov Date: Thu, 19 Jun 2025 16:20:26 +0300 Subject: [PATCH] bugfixes --- NN/exchanges/mexc_interface.py | 25 ++++++++++++++++++++----- core/enhanced_orchestrator.py | 10 +++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/NN/exchanges/mexc_interface.py b/NN/exchanges/mexc_interface.py index 74a84db..59a41c0 100644 --- a/NN/exchanges/mexc_interface.py +++ b/NN/exchanges/mexc_interface.py @@ -698,14 +698,29 @@ class MEXCInterface(ExchangeInterface): # MEXC API endpoint for account commission rates account_info = self._send_private_request('GET', 'account', {}) - # Extract commission rates from account info + # Extract commission rates from account info with null safety # MEXC typically returns commission rates in the account response maker_commission = account_info.get('makerCommission', 0) taker_commission = account_info.get('takerCommission', 0) - # Convert from basis points to decimal (MEXC uses basis points: 10 = 0.001%) - maker_rate = maker_commission / 100000 # Convert from basis points - taker_rate = taker_commission / 100000 + # Fix: Add null safety checks to prevent division by None + if maker_commission is None: + logger.warning("MEXC API returned None for makerCommission, using fallback") + maker_commission = 0 + + if taker_commission is None: + logger.warning("MEXC API returned None for takerCommission, using fallback") + taker_commission = 50 # 0.05% fallback + + # Convert from basis points to decimal with additional safety + try: + maker_rate = float(maker_commission) / 100000 # Convert from basis points + taker_rate = float(taker_commission) / 100000 + except (TypeError, ValueError) as e: + logger.error(f"Error converting commission rates: maker={maker_commission}, taker={taker_commission}, error={e}") + # Use safe fallback values + maker_rate = 0.0000 # 0.00% + taker_rate = 0.0005 # 0.05% logger.info(f"MEXC: Retrieved trading fees - Maker: {maker_rate*100:.3f}%, Taker: {taker_rate*100:.3f}%") @@ -720,7 +735,7 @@ class MEXCInterface(ExchangeInterface): except Exception as e: logger.error(f"Error getting MEXC trading fees: {e}") - # Return fallback values + # Return safe fallback values return { 'maker_rate': 0.0000, # 0.00% fallback 'taker_rate': 0.0005, # 0.05% fallback diff --git a/core/enhanced_orchestrator.py b/core/enhanced_orchestrator.py index 287bea3..4521a6e 100644 --- a/core/enhanced_orchestrator.py +++ b/core/enhanced_orchestrator.py @@ -2413,7 +2413,7 @@ class EnhancedTradingOrchestrator(TradingOrchestrator): # Get the best prediction best_pred = max(predictions, key=lambda p: p.overall_confidence) confidence = best_pred.overall_confidence - raw_action = best_pred.action + raw_action = best_pred.overall_action # Update dynamic thresholds periodically if hasattr(self, '_last_threshold_update'): @@ -2884,6 +2884,10 @@ class EnhancedTradingOrchestrator(TradingOrchestrator): async def start_cob_integration(self): """Start COB integration for real-time data feed""" try: + if self.cob_integration is None: + logger.warning("COB integration is disabled (cob_integration=None)") + return + logger.info("Starting COB integration for real-time market microstructure...") await self.cob_integration.start() logger.info("COB integration started successfully") @@ -2893,6 +2897,10 @@ class EnhancedTradingOrchestrator(TradingOrchestrator): async def stop_cob_integration(self): """Stop COB integration""" try: + if self.cob_integration is None: + logger.debug("COB integration is disabled (cob_integration=None)") + return + await self.cob_integration.stop() logger.info("COB integration stopped") except Exception as e: