import logging from typing import Dict, Optional from core.fee_calculator import FeeCalculator from core.entry_strategy import EntryStrategy logger = logging.getLogger(__name__) class StrategyValidator: """Validates opportunities before execution""" def __init__(self): self.fee_calculator = FeeCalculator() self.entry_strategy = EntryStrategy() self.min_net_rate = 0.0002 # 0.02% minimum net rate after fees async def validate_opportunity(self, opportunity: Dict, position_size: float, exchange_manager) -> tuple[bool, Optional[str], Optional[Dict]]: """Validate an opportunity before execution""" try: # Check profitability after fees profit_data = self.fee_calculator.calculate_net_profit(opportunity, position_size) if profit_data['net_profit_rate'] < self.min_net_rate: return False, f"Net profit rate too low: {profit_data['net_profit_rate']:.4%}", None # Check entry prices and slippage entry_prices = await self.entry_strategy.calculate_entry_prices( exchange_manager, opportunity['long_exchange'], opportunity['short_exchange'], opportunity['symbol'], position_size ) if not entry_prices: return False, "Could not calculate valid entry prices", None # Return validation result with profit data return True, "Valid opportunity", { 'profit_data': profit_data, 'entry_prices': entry_prices, } except Exception as e: logger.error(f"Error validating opportunity: {str(e)}") return False, f"Validation error: {str(e)}", None