浏览代码

Update market data retrieval to use asynchronous calls in multiple modules

- Refactored the market data retrieval method in ManagementCommands, ExternalEventMonitor, OrderFillProcessor, PositionMonitor, and RiskCleanupManager to utilize asynchronous calls, improving performance and responsiveness.
- Ensured consistent handling of market data across different components, enhancing overall system efficiency.
Carles Sentis 1 天之前
父节点
当前提交
7c3e4cb569

+ 1 - 1
src/commands/management_commands.py

@@ -165,7 +165,7 @@ class ManagementCommands:
                 
                 # Get current market price
                 symbol = f"{token}/USDC:USDC"
-                market_data = self.trading_engine.get_market_data(symbol)
+                market_data = await self.trading_engine.get_market_data(symbol)
                 
                 if not market_data or not market_data.get('ticker'):
                     await context.bot.send_message(chat_id=chat_id, text=f"❌ Could not fetch current price for {token}")

+ 1 - 1
src/monitoring/external_event_monitor.py

@@ -46,7 +46,7 @@ class ExternalEventMonitor:
             for token in tokens_to_check:
                 try:
                     symbol = f"{token}/USDC:USDC"
-                    market_data = self.trading_engine.get_market_data(symbol)
+                    market_data = await self.trading_engine.get_market_data(symbol)
                     
                     if not market_data or not market_data.get('ticker'):
                         continue

+ 1 - 1
src/monitoring/order_fill_processor.py

@@ -292,7 +292,7 @@ class OrderFillProcessor:
                         if self.notification_manager and sl_exchange_order_id:
                             current_price_for_notification = None
                             try:
-                                market_data_notify = self.trading_engine.get_market_data(symbol)
+                                market_data_notify = await self.trading_engine.get_market_data(symbol)
                                 if market_data_notify and market_data_notify.get('ticker'):
                                     current_price_for_notification = float(market_data_notify['ticker'].get('last', 0))
                             except:

+ 2 - 2
src/monitoring/position_monitor.py

@@ -52,7 +52,7 @@ class PositionMonitor:
             for token in tokens_to_check:
                 try:
                     symbol = f"{token}/USDC:USDC"
-                    market_data = self.trading_engine.get_market_data(symbol)
+                    market_data = await self.trading_engine.get_market_data(symbol)
                     
                     if not market_data or not market_data.get('ticker'):
                         continue
@@ -1070,7 +1070,7 @@ class PositionMonitor:
             # Estimate exit price from market data
             exit_price = 0
             try:
-                market_data = self.trading_engine.get_market_data(symbol)
+                market_data = await self.trading_engine.get_market_data(symbol)
                 if market_data and market_data.get('ticker'):
                     exit_price = float(market_data['ticker'].get('last', 0))
                     if exit_price <= 0:

+ 1 - 1
src/monitoring/risk_cleanup_manager.py

@@ -56,7 +56,7 @@ class RiskCleanupManager:
                     logger.warning(f"Invalid trigger order data for DB ID {order_db_id}, skipping: {trigger_order}")
                     continue
 
-                market_data = self.trading_engine.get_market_data(symbol)
+                market_data = await self.trading_engine.get_market_data(symbol)
                 if not market_data or not market_data.get('ticker'):
                     logger.warning(f"Could not fetch market data for {symbol} to check SL trigger {order_db_id}.")
                     continue

+ 1 - 1
trading_bot.py

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