diff --git a/RELEASES.md b/RELEASES.md index 7e7d1947049..773b782226d 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -23,6 +23,7 @@ None - Fixed logging `StdoutWriter` from also writing error logs (writers were duplicating error logs) - Fixed `BinanceWebSocketClient` to [new specification](https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams) which requires responding to pings with a pong containing the pings payload - Fixed Binance Futures `AccountBalance` calculations based on wallet and available balance +- Fixed `ExecAlgorithm` circular import issue for installed wheels (importing from `execution.algorithm` was a circular import) --- diff --git a/nautilus_trader/trading/trader.py b/nautilus_trader/trading/trader.py index ff983f96a93..6ca91204891 100644 --- a/nautilus_trader/trading/trader.py +++ b/nautilus_trader/trading/trader.py @@ -39,8 +39,6 @@ from nautilus_trader.core.correctness import PyCondition from nautilus_trader.core.uuid import UUID4 from nautilus_trader.data.engine import DataEngine -from nautilus_trader.execution.algorithm import ExecAlgorithm -from nautilus_trader.execution.engine import ExecutionEngine from nautilus_trader.model.identifiers import ComponentId from nautilus_trader.model.identifiers import ExecAlgorithmId from nautilus_trader.model.identifiers import StrategyId @@ -103,11 +101,15 @@ def __init__( portfolio: Portfolio, data_engine: DataEngine, risk_engine: RiskEngine, - exec_engine: ExecutionEngine, + exec_engine: Any, clock: Clock, has_controller: bool = False, loop: asyncio.AbstractEventLoop | None = None, ) -> None: + # Import here to avoid circular import issues + from nautilus_trader.execution.engine import ExecutionEngine + + PyCondition.type(exec_engine, ExecutionEngine, "exec_engine") super().__init__( clock=clock, component_id=trader_id, @@ -124,7 +126,7 @@ def __init__( self._actors: dict[ComponentId, Actor] = {} self._strategies: dict[StrategyId, Strategy] = {} - self._exec_algorithms: dict[ExecAlgorithmId, ExecAlgorithm] = {} + self._exec_algorithms: dict[ExecAlgorithmId, Any] = {} self._has_controller: bool = has_controller @property @@ -161,7 +163,7 @@ def strategies(self) -> list[Strategy]: """ return list(self._strategies.values()) - def exec_algorithms(self) -> list[ExecAlgorithm]: + def exec_algorithms(self) -> list[Any]: # ExecutonAlgorithm (circular import issues) """ Return the execution algorithms loaded in the trader. @@ -440,7 +442,7 @@ def add_strategies(self, strategies: list[Strategy]) -> None: for strategy in strategies: self.add_strategy(strategy) - def add_exec_algorithm(self, exec_algorithm: ExecAlgorithm) -> None: + def add_exec_algorithm(self, exec_algorithm: Any) -> None: """ Add the given execution algorithm to the trader. @@ -487,7 +489,7 @@ def add_exec_algorithm(self, exec_algorithm: ExecAlgorithm) -> None: self._log.info(f"Registered ExecAlgorithm {exec_algorithm}.") - def add_exec_algorithms(self, exec_algorithms: list[ExecAlgorithm]) -> None: + def add_exec_algorithms(self, exec_algorithms: list[Any]) -> None: """ Add the given execution algorithms to the trader.