This commit is contained in:
Ichinga Samuel
2024-11-08 05:41:23 +01:00
parent 4811aece5c
commit d9bd84bc2e
14 changed files with 361 additions and 282 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ async def test_bot():
bot.executor.timeout = 10
bot.add_strategies(strategies=strategies)
await bot.initialize()
await bot.executor.execute()
bot.executor.execute()
assert len(bot.executor.coroutines) == 1
assert len(bot.executor.coroutine_threads) == 1
assert bot.config.shutdown is True
+25
View File
@@ -0,0 +1,25 @@
import logging
from aiomql.lib.bot import Bot
from aiomql.contrib.strategies import Chaos
from aiomql.contrib.symbols import ForexSymbol
def test_bot_sync():
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
)
syms = ["BTCUSD", "SOLUSD", "ETHUSD"]
symbols = [ForexSymbol(name=sym) for sym in syms]
strategies = [Chaos(symbol=symbol, name="test_chaos") for symbol in symbols]
bot = Bot()
assert bot.config.shutdown is False
bot.executor.timeout = 10
bot.add_strategies(strategies=strategies)
bot.initialize_sync()
bot.executor.execute()
assert len(bot.executor.strategy_runners) == 3
assert len(bot.executor.coroutines) == 1
assert len(bot.executor.coroutine_threads) == 1
assert bot.config.shutdown is True
+14 -1
View File
@@ -9,6 +9,7 @@ class TestBotFactoryAndExecutor:
@classmethod
def setup_class(cls):
cls.bot = Bot()
cls.sync_bot = Bot()
@pytest.fixture(scope="class", autouse=True)
async def initialize(self):
@@ -18,6 +19,14 @@ class TestBotFactoryAndExecutor:
self.bot.add_coroutine(coroutine=self.coro_thread, on_separate_thread=True)
await self.bot.initialize()
@pytest.fixture(scope="class", autouse=True)
def initialize_sync(self):
self.sync_bot.add_coroutine(coroutine=self.coro_one)
self.sync_bot.add_coroutine(coroutine=self.coro_two)
self.sync_bot.add_function(function=self.fun_one)
self.sync_bot.add_coroutine(coroutine=self.coro_thread, on_separate_thread=True)
self.sync_bot.initialize_sync()
@staticmethod
def fun_one():
print("function one")
@@ -46,4 +55,8 @@ class TestBotFactoryAndExecutor:
# task_queue already added coroutine_thread
assert len(self.bot.executor.coroutine_threads) == 2
# def
def test_sync_add_workers(self):
assert len(self.sync_bot.executor.coroutines) == 3
assert len(self.sync_bot.executor.functions) == 1
# task_queue already added coroutine_thread
assert len(self.sync_bot.executor.coroutine_threads) == 2