Skip to content

Commit

Permalink
Refine docker RuntimeError (#1426)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmb7z authored Dec 28, 2023
1 parent d04aefe commit 0c866e7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions nautilus_trader/adapters/interactive_brokers/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,6 @@
from nautilus_trader.adapters.interactive_brokers.config import InteractiveBrokersGatewayConfig


try:
import docker
except ImportError as e:
raise RuntimeError("Docker required for Gateway, install via `pip install docker`") from e


class ContainerStatus(IntEnum):
NO_CONTAINER = 1
CONTAINER_CREATED = 2
Expand Down Expand Up @@ -81,9 +75,19 @@ def __init__(
self.read_only_api = read_only_api
self.host = host
self.port = port or self.PORTS[trading_mode]
self.log = logger or logging.getLogger("nautilus_trader")

try:
import docker

self._docker_module = docker
except ImportError as e:
raise RuntimeError(
"Docker required for Gateway, install via `pip install docker`",
) from e

self._docker = docker.from_env()
self._container = None
self.log = logger or logging.getLogger("nautilus_trader")
if start:
self.start(timeout)

Expand Down Expand Up @@ -189,7 +193,7 @@ def start(self, wait: int | None = 90):
def safe_start(self, wait: int = 90):
try:
self.start(wait=wait)
except docker.errors.APIError as e:
except self._docker_module.errors.APIError as e:
raise RuntimeError("Container already exists") from e

def stop(self):
Expand Down

0 comments on commit 0c866e7

Please sign in to comment.