diff --git a/pyproject.toml b/pyproject.toml index d3dc106..50a27e0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta" [project] name = "aiomql" -version = "3.17" +version = "3.18" readme = "README.md" requires-python = ">=3.10" classifiers = [ diff --git a/src/aiomql/bot_builder.py b/src/aiomql/bot_builder.py index 11c93f8..47bb2a6 100644 --- a/src/aiomql/bot_builder.py +++ b/src/aiomql/bot_builder.py @@ -51,14 +51,18 @@ class Bot: Raises: SystemExit if sign in was not successful """ - init = await self.account.sign_in() - if not init: - logger.warning(f"Unable to sign in to MetaTrder 5 Terminal") + try: + init = await self.account.sign_in() + if not init: + logger.warning(f"Unable to sign in to MetaTrder 5 Terminal") + raise SystemExit + logger.info("Login Successful") + await self.init_symbols() + self.executor.remove_workers() + self.add_coroutine(self.config.task_queue.start) + except Exception as err: + logger.error(f"{err}. Bot initialization failed") raise SystemExit - logger.info("Login Successful") - await self.init_symbols() - self.executor.remove_workers() - self.add_coroutine(self.config.task_queue.start) def add_function(self, func: Callable, **kwargs: dict): """Add a function to the executor. diff --git a/src/aiomql/core/config.py b/src/aiomql/core/config.py index 4446a77..aae67a8 100644 --- a/src/aiomql/core/config.py +++ b/src/aiomql/core/config.py @@ -40,7 +40,7 @@ class Config: record_trades: bool = True filename: str = "aiomql.json" win_percentage: float = 0.85 - records_dir = Path.home() / "Documents" / "Aiomql" / "Trade Records" + records_dir = Path(Path.home() / "Documents" / "Aiomql" / "Trade Records").mkdir(parents=True, exist_ok=True) config_dir: str = '' _initialize = True state: dict = {} @@ -62,6 +62,8 @@ class Config: def __setattr__(self, key, value): if key == 'root_dir': value = Path(value).absolute().resolve() + if key == 'records_dir': + value = self.create_records_dir(value) super().__setattr__(key, value) @staticmethod @@ -90,6 +92,15 @@ class Config: except Exception as _: return + def create_records_dir(self, records_dir: str | Path): + """Create records directory if it does not exist""" + try: + records_dir = Path(records_dir).absolute().resolve() if isinstance(records_dir, str) else records_dir + records_dir.mkdir(parents=True, exist_ok=True) + return records_dir + except Exception as _: + logger.warning("Unable to create records directory") + def load_config(self, file: str = None, reload: bool = True, filename: str = None, config_dir: str = ''): """Load configuration settings from a file.""" if not (self._initialize or reload): @@ -105,7 +116,6 @@ class Config: data = json.load(fh) fh.close() [setattr(self, key, value) for key, value in data.items()] - self.records_dir.mkdir(parents=True, exist_ok=True) if self.records_dir else ... def account_info(self) -> dict[str, int | str]: """Returns Account login details as found in the config object if available