Procházet zdrojové kódy

Refactor stop loss retrieval logic in InfoCommands - Enhanced the method for identifying pending stop losses by first retrieving all pending trigger orders and then filtering them based on type and parent order reference ID. Improved logging for better debugging and clarity in matching stop losses to their respective orders.

Carles Sentis před 4 dny
rodič
revize
6e7803b227
1 změnil soubory, kde provedl 23 přidání a 7 odebrání
  1. 23 7
      src/commands/info_commands.py

+ 23 - 7
src/commands/info_commands.py

@@ -227,17 +227,33 @@ class InfoCommands:
                                 bot_ref_id = order_in_db.get('bot_order_ref_id')
                                 if bot_ref_id:
                                     # Look for pending stop losses with this order as parent
-                                    pending_sls = stats.get_orders_by_status(
-                                        status='pending_trigger', 
-                                        order_type_filter='stop_limit_trigger',
-                                        parent_bot_order_ref_id=bot_ref_id
-                                    )
+                                    # First, get all pending stop losses to debug
+                                    all_pending_sls = stats.get_orders_by_status('pending_trigger')
+                                    logger.info(f"DEBUG: Found {len(all_pending_sls)} total pending trigger orders")
                                     
-                                    if pending_sls:
-                                        sl_order = pending_sls[0]  # Should only be one
+                                    # Filter for stop_limit_trigger type and matching parent
+                                    matching_sls = []
+                                    for sl in all_pending_sls:
+                                        sl_type = sl.get('type', '').upper()
+                                        sl_parent = sl.get('parent_bot_order_ref_id', '')
+                                        
+                                        logger.info(f"DEBUG: Checking SL - Type: '{sl_type}', Parent: '{sl_parent}', Looking for: '{bot_ref_id}'")
+                                        
+                                        if (sl_type == 'STOP_LIMIT_TRIGGER' and 
+                                            sl_parent == bot_ref_id):
+                                            matching_sls.append(sl)
+                                            logger.info(f"DEBUG: Found matching SL - Price: {sl.get('price')}, Side: {sl.get('side')}")
+                                    
+                                    if matching_sls:
+                                        sl_order = matching_sls[0]  # Should only be one
                                         sl_price = sl_order.get('price', 0)
                                         sl_side = sl_order.get('side', '').upper()
                                         orders_text += f"   🛑 Pending SL: {sl_side} @ {formatter.format_price_with_symbol(sl_price, symbol)} (activates when filled)\n"
+                                        logger.info(f"DEBUG: Added SL display text for order {order_id}")
+                                    else:
+                                        logger.info(f"DEBUG: No matching SL found for order {order_id} with bot_ref {bot_ref_id}")
+                            else:
+                                logger.info(f"DEBUG: Order {order_id} not found in database")
                         
                         orders_text += "\n"