Pārlūkot izejas kodu

Update notification method calls in PendingOrdersManager and RiskManager to use send_generic_notification

- Replaced send_notification with send_generic_notification in PendingOrdersManager for pending stop loss and order placement notifications.
- Updated RiskManager to use send_generic_notification for hard exit execution and failure notifications, improving consistency in notification handling.
Carles Sentis 21 stundas atpakaļ
vecāks
revīzija
46e2159879

+ 2 - 2
src/monitoring/pending_orders_manager.py

@@ -88,7 +88,7 @@ class PendingOrdersManager:
                 f"Stop Price: ${stop_price:.4f}\n"
                 f"Expires: {expires_hours}h"
             )
-            await self.notification_manager.send_notification(message)
+            await self.notification_manager.send_generic_notification(message)
             
         except Exception as e:
             logger.error(f"Error adding pending stop loss: {e}")
@@ -191,7 +191,7 @@ class PendingOrdersManager:
                         f"Stop Price: ${stop_price:.4f}\n"
                         f"Order ID: {order_id}"
                     )
-                    await self.notification_manager.send_notification(message)
+                    await self.notification_manager.send_generic_notification(message)
                     logger.info(f"Placed stop loss: {symbol} {sl_size} @ ${stop_price}")
                     
                 else:

+ 34 - 37
src/monitoring/risk_manager.py

@@ -101,45 +101,42 @@ class RiskManager:
             logger.warning(f"Hard exit triggered for {symbol}: ROE {roe:.2%} < {self.hard_exit_roe:.2%}")
             
             # Place market order to close position
-            order_result = await self.hl_client.place_order(
-                symbol=symbol,
+            full_symbol = f"{symbol}/USDC:USDC"
+            order_result, error_msg = self.hl_client.place_market_order(
+                symbol=full_symbol,
                 side=side,
-                size=order_size,
-                order_type='market',
-                reduce_only=True
+                amount=order_size
             )
             
-            if order_result and 'response' in order_result:
-                response = order_result['response']
-                if response.get('type') == 'order':
-                    
-                    # Send alert notification
-                    message = (
-                        f"🚨 HARD EXIT EXECUTED\n"
-                        f"Token: {symbol}\n"
-                        f"ROE: {roe:.2%}\n"
-                        f"Threshold: {self.hard_exit_roe:.2%}\n"
-                        f"Size: {order_size:.4f}\n"
-                        f"Est. PnL: ${unrealized_pnl:.3f}\n"
-                        f"Risk management action taken!"
-                    )
-                    
-                    await self.notification_manager.send_notification(message)
-                    logger.info(f"Hard exit executed for {symbol}: {order_size} @ ROE {roe:.2%}")
-                    
-                else:
-                    logger.error(f"Failed to execute hard exit for {symbol}: {response}")
-                    
-                    # Send failure notification
-                    error_message = (
-                        f"❌ HARD EXIT FAILED\n"
-                        f"Token: {symbol}\n"
-                        f"ROE: {roe:.2%}\n"
-                        f"Could not place market order!\n"
-                        f"Manual intervention required!"
-                    )
-                    await self.notification_manager.send_notification(error_message)
-                    
+            if order_result and not error_msg:
+                # Send alert notification
+                message = (
+                    f"🚨 HARD EXIT EXECUTED\n"
+                    f"Token: {symbol}\n"
+                    f"ROE: {roe:.2%}\n"
+                    f"Threshold: {self.hard_exit_roe:.2%}\n"
+                    f"Size: {order_size:.4f}\n"
+                    f"Est. PnL: ${unrealized_pnl:.3f}\n"
+                    f"Risk management action taken!"
+                )
+                
+                await self.notification_manager.send_generic_notification(message)
+                logger.info(f"Hard exit executed for {symbol}: {order_size} @ ROE {roe:.2%}")
+                
+            else:
+                logger.error(f"Failed to execute hard exit for {symbol}: {error_msg}")
+                
+                # Send failure notification
+                error_message = (
+                    f"❌ HARD EXIT FAILED\n"
+                    f"Token: {symbol}\n"
+                    f"ROE: {roe:.2%}\n"
+                    f"Could not place market order!\n"
+                    f"Error: {error_msg}\n"
+                    f"Manual intervention required!"
+                )
+                await self.notification_manager.send_generic_notification(error_message)
+                
         except Exception as e:
             logger.error(f"Error executing hard exit for {position['symbol']}: {e}")
             
@@ -151,7 +148,7 @@ class RiskManager:
                 f"Error: {str(e)}\n"
                 f"Manual intervention required!"
             )
-            await self.notification_manager.send_notification(error_message)
+            await self.notification_manager.send_generic_notification(error_message)
             
     async def get_risk_status(self) -> Dict:
         """Get current risk status"""

+ 1 - 1
trading_bot.py

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