This commit is contained in:
Ichinga Samuel
2024-10-29 14:03:32 +01:00
parent 5f6d3666ee
commit 2c46e18528
6 changed files with 12 additions and 29 deletions
@@ -8,7 +8,7 @@ from ...core.constants import AccountTradeMode, AccountMarginMode, AccountStopOu
class BackTestAccount:
login: int = 0
trade_mode: AccountTradeMode = AccountTradeMode.DEMO
leverage: float = 0
leverage: float = 1
limit_orders: float = 0
margin_so_mode: AccountStopOutMode = AccountStopOutMode.PERCENT
trade_allowed: bool = True
@@ -612,18 +612,11 @@ class BackTestEngine:
# @error_handler
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)
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
current_time = round_up(current_time, timeframe.seconds)
start = datetime.fromtimestamp(current_time, tz=UTC)
rates = await self.mt5.copy_rates_from(symbol, timeframe, start, count)
return rates
rates = self.rates[symbol][timeframe]
+3 -5
View File
@@ -1,14 +1,13 @@
import logging
from aiomql.lib.bot import Bot
from aiomql.core import Config
from aiomql.contrib.strategies import FingerTrap, Chaos
from aiomql.contrib.strategies import 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']
syms = ['BTCUSD', 'SOLUSD', 'ETHUSD']
symbols = [ForexSymbol(name=sym) for sym in syms]
stgs = [Chaos(symbol=symbol, name='test_chaos') for symbol in symbols]
bot = Bot()
@@ -16,9 +15,8 @@ async def test_bot():
bot.executor.timeout = 30
bot.add_strategies(strategies=stgs)
await bot.initialize()
await bot.executor.execute()
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
+2 -2
View File
@@ -3,7 +3,7 @@ from datetime import datetime, UTC
from aiomql import TimeFrame
from aiomql.contrib.backtesting import BackTestEngine
from aiomql.contrib.backtesting.get_data import GetData
from aiomql._utils import round_down
from aiomql._utils import round_down, round_up
from aiomql.core.constants import OrderType, TradeAction
import pytest
@@ -136,8 +136,8 @@ class TestBackTestEngine:
tf = TimeFrame.H2
start_pos = 2
rates = await self.bte.get_rates_from_pos(symbol='BTCUSD', timeframe=tf, start_pos=start_pos, count=24)
assert int(rates[-1][0]) == round_down(int(now.replace(hour=7).timestamp()), tf.seconds)
assert len(rates) == 24
assert int(rates[-1][0]) == round_down(int(now.replace(hour = now.hour - start_pos).timestamp()), tf.seconds)
async def test_get_rates_from_pos2(self, bte2):
now = datetime(2024, 2, 4, 12, 15, tzinfo=UTC)
+2 -3
View File
@@ -41,9 +41,8 @@ class TestBotFactoryAndExecutor:
await asyncio.sleep(1)
def test_add_workers(self):
assert len(self.bot.executor.coroutines) == 2
# exit function already added
assert len(self.bot.executor.functions) == 2
assert len(self.bot.executor.coroutines) == 3
assert len(self.bot.executor.functions) == 1
# task_queue already added coroutine_thread
assert len(self.bot.executor.coroutine_threads) == 2
-7
View File
@@ -1,7 +0,0 @@
actual_profit,deal,ask,ltf,htf,price,order,slow_ema,symbol,expected_profit,lcc,date,bid,name,win,hcc,fast_ema,volume,closed
0,127446532,643587.63,TIMEFRAME_M1,TIMEFRAME_M2,643587.63,436128326,20,Volatility 75 Index,0,100,2021-01-01 00:00:00.000000,643457.63,Chaos,False,100,8,0.001,False
0,337655374,2268.02,TIMEFRAME_M1,TIMEFRAME_M2,2267.34,580347053,20,Volatility 100 Index,0,100,2021-01-01 00:00:00.000000,2267.34,Chaos,False,100,8,0.5,False
0,895556166,189.1722,TIMEFRAME_M1,TIMEFRAME_M2,189.1452,645695617,20,Volatility 50 Index,0,100,2021-01-01 00:00:00.000000,189.1452,Chaos,False,100,8,4.0,False
0,215199127,643587.63,TIMEFRAME_M1,TIMEFRAME_M2,643587.63,274191555,20,Volatility 75 Index,0,100,2021-01-01 00:00:00.000000,643457.63,Chaos,False,100,8,0.001,False
0,949649264,2268.02,TIMEFRAME_M1,TIMEFRAME_M2,2268.02,740685256,20,Volatility 100 Index,0,100,2021-01-01 00:00:00.000000,2267.34,Chaos,False,100,8,0.5,False
0,939601387,189.1722,TIMEFRAME_M1,TIMEFRAME_M2,189.1452,969153963,20,Volatility 50 Index,0,100,2021-01-01 00:00:00.000000,189.1452,Chaos,False,100,8,4.0,False
1 actual_profit deal ask ltf htf price order slow_ema symbol expected_profit lcc date bid name win hcc fast_ema volume closed
2 0 127446532 643587.63 TIMEFRAME_M1 TIMEFRAME_M2 643587.63 436128326 20 Volatility 75 Index 0 100 2021-01-01 00:00:00.000000 643457.63 Chaos False 100 8 0.001 False
3 0 337655374 2268.02 TIMEFRAME_M1 TIMEFRAME_M2 2267.34 580347053 20 Volatility 100 Index 0 100 2021-01-01 00:00:00.000000 2267.34 Chaos False 100 8 0.5 False
4 0 895556166 189.1722 TIMEFRAME_M1 TIMEFRAME_M2 189.1452 645695617 20 Volatility 50 Index 0 100 2021-01-01 00:00:00.000000 189.1452 Chaos False 100 8 4.0 False
5 0 215199127 643587.63 TIMEFRAME_M1 TIMEFRAME_M2 643587.63 274191555 20 Volatility 75 Index 0 100 2021-01-01 00:00:00.000000 643457.63 Chaos False 100 8 0.001 False
6 0 949649264 2268.02 TIMEFRAME_M1 TIMEFRAME_M2 2268.02 740685256 20 Volatility 100 Index 0 100 2021-01-01 00:00:00.000000 2267.34 Chaos False 100 8 0.5 False
7 0 939601387 189.1722 TIMEFRAME_M1 TIMEFRAME_M2 189.1452 969153963 20 Volatility 50 Index 0 100 2021-01-01 00:00:00.000000 189.1452 Chaos False 100 8 4.0 False