123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- #!/usr/bin/env python3
- """
- Position Monitor Integration
- Simple replacement for the complex external event monitoring.
- Uses the new SimplePositionTracker for clean position management.
- """
- import logging
- import asyncio
- from datetime import datetime, timezone
- from typing import Optional
- from .simple_position_tracker import SimplePositionTracker
- logger = logging.getLogger(__name__)
- class PositionMonitorIntegration:
- """Integration layer to replace complex external event monitoring."""
-
- def __init__(self, trading_engine, notification_manager):
- self.trading_engine = trading_engine
- self.notification_manager = notification_manager
- self.position_tracker = SimplePositionTracker(trading_engine, notification_manager)
- self.last_check_time: Optional[datetime] = None
-
- async def run_monitoring_cycle(self):
- """Main monitoring cycle - replaces the complex external event monitoring."""
- try:
- logger.debug("🔄 Starting simplified position monitoring cycle")
-
- # Simple position change detection and notifications
- await self.position_tracker.check_all_position_changes()
-
- self.last_check_time = datetime.now(timezone.utc)
- logger.debug("✅ Completed simplified position monitoring cycle")
-
- except Exception as e:
- logger.error(f"❌ Error in position monitoring cycle: {e}")
-
- async def check_price_alarms(self):
- """Price alarm checking (can be kept separate if needed)."""
- # This can remain from the original external event monitor if needed
- pass
-
- def get_status(self) -> dict:
- """Get monitoring status."""
- return {
- 'last_check_time': self.last_check_time.isoformat() if self.last_check_time else None,
- 'monitor_type': 'simplified_position_tracker'
- }
- # Example usage in market_monitor.py:
- """
- # Replace this complex call:
- # await self.external_event_monitor._check_external_trades()
- # With this simple call:
- await self.position_monitor_integration.run_monitoring_cycle()
- """
|