Skip to content

Commit

Permalink
Fix ExecAlgorithm circular import issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cjdsellers committed Mar 12, 2024
1 parent de27621 commit df4e468
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

---

Expand Down
16 changes: 9 additions & 7 deletions nautilus_trader/trading/trader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit df4e468

Please sign in to comment.