This commit is contained in:
Ichinga Samuel
2024-01-25 00:54:33 +01:00
parent 7653bb288f
commit 3f53df8375
3 changed files with 24 additions and 10 deletions
+1 -1
View File
@@ -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 = [
+11 -7
View File
@@ -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.
+12 -2
View File
@@ -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