"""Strategy Engine Service entry point.""" import asyncio import logging from pathlib import Path from shared.broker import RedisBroker from strategy_engine.config import StrategyConfig from strategy_engine.engine import StrategyEngine from strategy_engine.plugin_loader import load_strategies logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) # The strategies directory lives alongside the installed package STRATEGIES_DIR = Path(__file__).parent.parent.parent.parent / "strategies" async def run() -> None: config = StrategyConfig() broker = RedisBroker(config.redis_url) strategies_dir = STRATEGIES_DIR strategies = load_strategies(strategies_dir) # Configure each strategy with params from config for strategy in strategies: params = config.strategy_params.get(strategy.name, {}) strategy.configure(params) logger.info( "Loaded %d strategies: %s", len(strategies), [s.name for s in strategies], ) engine = StrategyEngine(broker=broker, strategies=strategies) try: for symbol in config.symbols: stream = f"candles.{symbol.replace('/', '_')}" last_id = "$" logger.info("Starting engine loop for stream=%s", stream) while True: last_id = await engine.process_once(stream, last_id) finally: await broker.close() def main() -> None: asyncio.run(run()) if __name__ == "__main__": main()