Kaynağa Gözat

Increment bot version to 2.6.303 and improve position side determination logic in PositionTracker

- Updated BOT_VERSION to 2.6.303.
- Enhanced position side determination by using the 'side' field from the exchange for more reliable trade classification.
- Added fallback logic to use contracts sign if the 'side' field is missing, with a warning log for better traceability.
Carles Sentis 22 saat önce
ebeveyn
işleme
6188fbd11a
2 değiştirilmiş dosya ile 15 ekleme ve 3 silme
  1. 14 2
      src/commands/management_commands.py
  2. 1 1
      trading_bot.py

+ 14 - 2
src/commands/management_commands.py

@@ -651,8 +651,20 @@ Will trigger when {token} price moves {alarm['direction']} {target_price_str}
                                 token = symbol.split('/')[0] if '/' in symbol else symbol.split(':')[0]
                                 
                                 # Create a new trade lifecycle for this existing position
-                                side = 'buy' if size > 0 else 'sell'
-                                position_side = 'long' if size > 0 else 'short'
+                                # Use the side field from exchange (more reliable than contracts sign)
+                                exchange_side = position.get('side', '').lower()
+                                if exchange_side == 'long':
+                                    side = 'buy'
+                                    position_side = 'long'
+                                elif exchange_side == 'short':
+                                    side = 'sell' 
+                                    position_side = 'short'
+                                else:
+                                    # Fallback to contracts sign if side field missing
+                                    side = 'buy' if size > 0 else 'sell'
+                                    position_side = 'long' if size > 0 else 'short'
+                                    logger.warning(f"Using contracts sign fallback for {token}: size={size}, exchange_side='{exchange_side}'")
+                                
                                 entry_price = float(position.get('entryPrice', 0))
                                 
                                 if entry_price > 0:  # Valid position data

+ 1 - 1
trading_bot.py

@@ -14,7 +14,7 @@ from datetime import datetime
 from pathlib import Path
 
 # Bot version
-BOT_VERSION = "2.6.302"
+BOT_VERSION = "2.6.303"
 
 # Add src directory to Python path
 sys.path.insert(0, str(Path(__file__).parent / "src"))