position_monitor_integration.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python3
  2. """
  3. Position Monitor Integration
  4. Simple replacement for the complex external event monitoring.
  5. Uses the new SimplePositionTracker for clean position management.
  6. """
  7. import logging
  8. import asyncio
  9. from datetime import datetime, timezone
  10. from typing import Optional
  11. from .simple_position_tracker import SimplePositionTracker
  12. logger = logging.getLogger(__name__)
  13. class PositionMonitorIntegration:
  14. """Integration layer to replace complex external event monitoring."""
  15. def __init__(self, trading_engine, notification_manager):
  16. self.trading_engine = trading_engine
  17. self.notification_manager = notification_manager
  18. self.position_tracker = SimplePositionTracker(trading_engine, notification_manager)
  19. self.last_check_time: Optional[datetime] = None
  20. async def run_monitoring_cycle(self):
  21. """Main monitoring cycle - replaces the complex external event monitoring."""
  22. try:
  23. logger.debug("🔄 Starting simplified position monitoring cycle")
  24. # Simple position change detection and notifications
  25. await self.position_tracker.check_all_position_changes()
  26. self.last_check_time = datetime.now(timezone.utc)
  27. logger.debug("✅ Completed simplified position monitoring cycle")
  28. except Exception as e:
  29. logger.error(f"❌ Error in position monitoring cycle: {e}")
  30. async def check_price_alarms(self):
  31. """Price alarm checking (can be kept separate if needed)."""
  32. # This can remain from the original external event monitor if needed
  33. pass
  34. def get_status(self) -> dict:
  35. """Get monitoring status."""
  36. return {
  37. 'last_check_time': self.last_check_time.isoformat() if self.last_check_time else None,
  38. 'monitor_type': 'simplified_position_tracker'
  39. }
  40. # Example usage in market_monitor.py:
  41. """
  42. # Replace this complex call:
  43. # await self.external_event_monitor._check_external_trades()
  44. # With this simple call:
  45. await self.position_monitor_integration.run_monitoring_cycle()
  46. """