mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-08-19 14:58:07 +00:00
v4
This commit is contained in:
@@ -613,12 +613,16 @@ class BackTestEngine:
|
|||||||
async def get_rates_from_pos(self, *, symbol: str, timeframe: TimeFrame, start_pos: int, count: int) -> np.ndarray:
|
async def get_rates_from_pos(self, *, symbol: str, timeframe: TimeFrame, start_pos: int, count: int) -> np.ndarray:
|
||||||
if self.use_terminal:
|
if self.use_terminal:
|
||||||
# Todo: Optimize this!!!
|
# Todo: Optimize this!!!
|
||||||
now = datetime.now(tz=UTC).timestamp()
|
# now = datetime.now(tz=UTC).timestamp()
|
||||||
b_now = self.cursor.time
|
# b_now = self.cursor.time
|
||||||
diff = ceil((now - b_now) / timeframe.seconds)
|
# diff = ceil((now - b_now) / timeframe.seconds)
|
||||||
start_pos = int(diff + start_pos)
|
# start_pos = int(diff + start_pos)
|
||||||
# print('hehk', start_pos, count)
|
# # print('hehk', start_pos, count)
|
||||||
res = await self.mt5.copy_rates_from_pos(symbol, timeframe, 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
|
return res
|
||||||
|
|
||||||
rates = self.rates[symbol][timeframe]
|
rates = self.rates[symbol][timeframe]
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ class EventManager:
|
|||||||
await self.backtest_engine.tracker()
|
await self.backtest_engine.tracker()
|
||||||
self.backtest_engine.next()
|
self.backtest_engine.next()
|
||||||
self.condition.notify_all()
|
self.condition.notify_all()
|
||||||
# print(f"Time: {self.backtest_engine.cursor.time}")
|
|
||||||
if self.backtest_engine.cursor.time % 3600 == 0:
|
if self.backtest_engine.cursor.time % 3600 == 0:
|
||||||
print(datetime.strftime(self.backtest_engine.cursor.time, "%Y-%m-%d %H:%M:%S"))
|
print(datetime.strftime(self.backtest_engine.cursor.time, "%Y-%m-%d %H:%M:%S"))
|
||||||
if self.backtest_engine.stop_testing:
|
if self.backtest_engine.stop_testing:
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
Reference in New Issue
Block a user