mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-23 00:38:07 +00:00
v3.17
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "aiomql"
|
name = "aiomql"
|
||||||
version = "3.16"
|
version = "3.17"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
requires-python = ">=3.10"
|
requires-python = ">=3.10"
|
||||||
classifiers = [
|
classifiers = [
|
||||||
|
|||||||
+13
-2
@@ -64,8 +64,7 @@ class Account(AccountInfo):
|
|||||||
bool: True if login was successful else False
|
bool: True if login was successful else False
|
||||||
"""
|
"""
|
||||||
acc = self.get_dict(include={'login', 'server', 'password'})
|
acc = self.get_dict(include={'login', 'server', 'password'})
|
||||||
await self.mt5.initialize(**acc, path=self.config.path)
|
self.connected = await self._login(acc=acc)
|
||||||
self.connected = await self.mt5.login(**acc)
|
|
||||||
if self.connected:
|
if self.connected:
|
||||||
await self.refresh()
|
await self.refresh()
|
||||||
self.symbols = await self.symbols_get()
|
self.symbols = await self.symbols_get()
|
||||||
@@ -73,6 +72,18 @@ class Account(AccountInfo):
|
|||||||
await self.mt5.shutdown()
|
await self.mt5.shutdown()
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
async def _login(self, *, acc:dict, tries=3):
|
||||||
|
res = False
|
||||||
|
if tries == 0:
|
||||||
|
return False
|
||||||
|
ini = await self.mt5.initialize(**acc, path=self.config.path)
|
||||||
|
if ini:
|
||||||
|
res = await self.mt5.login(**acc)
|
||||||
|
if ini and res:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return await self._login(acc=acc, tries=tries-1)
|
||||||
|
|
||||||
def has_symbol(self, symbol: str | SymbolInfo):
|
def has_symbol(self, symbol: str | SymbolInfo):
|
||||||
"""Checks to see if a symbol is available for a trading account.
|
"""Checks to see if a symbol is available for a trading account.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
from concurrent.futures import ProcessPoolExecutor
|
||||||
from typing import Type, Iterable, TypeVar, Callable, Coroutine
|
from typing import Type, Iterable, TypeVar, Callable, Coroutine
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
@@ -35,6 +36,14 @@ class Bot:
|
|||||||
self.symbols = set()
|
self.symbols = set()
|
||||||
self.executor = Executor(bot=self)
|
self.executor = Executor(bot=self)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def run_bots(cls, bots: dict[Callable: dict] = None, num_workers: int = None):
|
||||||
|
"""Run multiple bots at the same time."""
|
||||||
|
num_workers = num_workers or len(bots) * 2
|
||||||
|
with ProcessPoolExecutor(max_workers=num_workers) as executor:
|
||||||
|
for bot, kwargs in bots.items():
|
||||||
|
executor.submit(bot, **kwargs)
|
||||||
|
|
||||||
async def initialize(self):
|
async def initialize(self):
|
||||||
"""Prepares the bot by signing in to the trading account and initializing the symbols for the trading session.
|
"""Prepares the bot by signing in to the trading account and initializing the symbols for the trading session.
|
||||||
Starts the global task queue.
|
Starts the global task queue.
|
||||||
@@ -44,7 +53,7 @@ class Bot:
|
|||||||
"""
|
"""
|
||||||
init = await self.account.sign_in()
|
init = await self.account.sign_in()
|
||||||
if not init:
|
if not init:
|
||||||
logger.warning("Unable to sign in to MetaTrder 5 Terminal")
|
logger.warning(f"Unable to sign in to MetaTrder 5 Terminal")
|
||||||
raise SystemExit
|
raise SystemExit
|
||||||
logger.info("Login Successful")
|
logger.info("Login Successful")
|
||||||
await self.init_symbols()
|
await self.init_symbols()
|
||||||
|
|||||||
Reference in New Issue
Block a user