From 5f6d3666eecefd307d7888a77d4a10f99e99bc72 Mon Sep 17 00:00:00 2001 From: Ichinga Samuel Date: Mon, 28 Oct 2024 17:12:52 +0100 Subject: [PATCH] v4 --- .../contrib/backtesting/backtest_engine.py | 16 ++++++++----- src/aiomql/core/event_manager.py | 1 - tests/live/integration/test_backtesting.py | 0 tests/live/integration/test_bot.py | 24 +++++++++++++++++++ 4 files changed, 34 insertions(+), 7 deletions(-) delete mode 100644 tests/live/integration/test_backtesting.py create mode 100644 tests/live/integration/test_bot.py diff --git a/src/aiomql/contrib/backtesting/backtest_engine.py b/src/aiomql/contrib/backtesting/backtest_engine.py index 829b8a6..8b4ecc2 100644 --- a/src/aiomql/contrib/backtesting/backtest_engine.py +++ b/src/aiomql/contrib/backtesting/backtest_engine.py @@ -613,12 +613,16 @@ class BackTestEngine: async def get_rates_from_pos(self, *, symbol: str, timeframe: TimeFrame, start_pos: int, count: int) -> np.ndarray: if self.use_terminal: # Todo: Optimize this!!! - now = datetime.now(tz=UTC).timestamp() - b_now = self.cursor.time - diff = ceil((now - b_now) / timeframe.seconds) - start_pos = int(diff + start_pos) - # print('hehk', start_pos, count) - res = await self.mt5.copy_rates_from_pos(symbol, timeframe, start_pos, count) + # now = datetime.now(tz=UTC).timestamp() + # b_now = self.cursor.time + # diff = ceil((now - b_now) / timeframe.seconds) + # start_pos = int(diff + start_pos) + # # print('hehk', start_pos, count) + # res = await self.mt5.copy_rates_from_pos(symbol, timeframe, start_pos, count) + current_time = self.cursor.time if start_pos == 0 else self.cursor.time - start_pos * timeframe.seconds + start = current_time - count * timeframe.seconds + start = datetime.fromtimestamp(start, tz=UTC) + rates = self.mt5.copy_rates_from(symbol, timeframe, start, count) return res rates = self.rates[symbol][timeframe] diff --git a/src/aiomql/core/event_manager.py b/src/aiomql/core/event_manager.py index fbb9a52..668a112 100644 --- a/src/aiomql/core/event_manager.py +++ b/src/aiomql/core/event_manager.py @@ -52,7 +52,6 @@ class EventManager: await self.backtest_engine.tracker() self.backtest_engine.next() self.condition.notify_all() - # print(f"Time: {self.backtest_engine.cursor.time}") if self.backtest_engine.cursor.time % 3600 == 0: print(datetime.strftime(self.backtest_engine.cursor.time, "%Y-%m-%d %H:%M:%S")) if self.backtest_engine.stop_testing: diff --git a/tests/live/integration/test_backtesting.py b/tests/live/integration/test_backtesting.py deleted file mode 100644 index e69de29..0000000 diff --git a/tests/live/integration/test_bot.py b/tests/live/integration/test_bot.py new file mode 100644 index 0000000..e6a5abd --- /dev/null +++ b/tests/live/integration/test_bot.py @@ -0,0 +1,24 @@ +import logging + +from aiomql.lib.bot import Bot +from aiomql.core import Config +from aiomql.contrib.strategies import FingerTrap, Chaos +from aiomql.contrib.symbols import ForexSymbol + + +async def test_bot(): + logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') + syms = ['Volatility 75 Index', 'Volatility 100 Index', 'Volatility 50 Index'] + symbols = [ForexSymbol(name=sym) for sym in syms] + stgs = [Chaos(symbol=symbol, name='test_chaos') for symbol in symbols] + bot = Bot() + assert bot.config.shutdown is False + bot.executor.timeout = 30 + bot.add_strategies(strategies=stgs) + await bot.initialize() + assert bot.executor.no_of_running_strategies == 3 + assert len(bot.executor.coroutines) == 1 + assert len(bot.executor.coroutine_threads) == 1 + assert len(bot.executor.tasks) == 5 + assert bot.config.shutdown is True +