Skip to content

Commit

Permalink
v4.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Ichinga-Samuel committed Dec 1, 2024
1 parent 9043d42 commit 8a4f5fe
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 42 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "aiomql"
version = "4.0.5"
version = "4.0.6"
readme = "README.md"
requires-python = ">=3.11"
classifiers = [
Expand Down
1 change: 1 addition & 0 deletions src/aiomql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .core import *
from .lib import *
from .contrib import *
from ._utils import *
50 changes: 24 additions & 26 deletions src/aiomql/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,33 @@

logger = getLogger(__name__)


async def backtest_sleep(secs: float):
async def backtest_sleep(secs):
"""An async sleep function for use during backtesting."""
config = Config()
btc = config.backtest_controller
try:
if btc.parties == 2:
steps = int(secs) // config.backtest_engine.speed
steps = max(steps, 1)
config.backtest_engine.fast_forward(steps=steps)
btc.wait()

elif btc.parties > 2:
_time = config.backtest_engine.cursor.time + secs
while _time > config.backtest_engine.cursor.time:
btc.wait()
else:
btc.wait()
except Exception as err:
btc.wait()
logger.error("Error: %s in backtest_sleep", err)


# async def backtest_sleep(secs):
# """An async sleep function for use during backtesting."""
# btc = BackTestController()
sleep = config.backtest_engine.cursor.time + secs
while sleep > config.backtest_engine.cursor.time:
await asyncio.sleep(0)


# async def backtest_sleep(secs: float):
# config = Config()
# sleep = config.backtest_engine.cursor.time + secs
# while sleep > config.backtest_engine.cursor.time:
# btc = config.backtest_controller
# try:
# if btc.parties == 2:
# steps = int(secs) // config.backtest_engine.speed
# steps = max(steps, 1)
# config.backtest_engine.fast_forward(steps=steps)
# btc.wait()
#
# elif btc.parties > 2:
# _time = config.backtest_engine.cursor.time + secs
# while _time > config.backtest_engine.cursor.time:
# btc.wait()
# else:
# btc.wait()
# except Exception as err:
# btc.wait()
# logger.error("Error: %s in backtest_sleep", err)


def dict_to_string(data: dict, multi=False) -> str:
Expand Down
15 changes: 7 additions & 8 deletions src/aiomql/lib/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from ..core.models import OrderSendResult, TradePosition
from ..core.config import Config
from .positions import Positions
from .._utils import backtest_sleep

logger = getLogger(__name__)

Expand All @@ -26,13 +25,13 @@ def delta(obj: time) -> timedelta:
return timedelta(hours=obj.hour, minutes=obj.minute, seconds=obj.second, microseconds=obj.microsecond)


# async def backtest_sleep(secs):
# """An async sleep function for use during backtesting."""
# btc = BackTestController()
# config = Config()
# sleep = config.backtest_engine.cursor.time + secs
# while sleep > config.backtest_engine.cursor.time:
# btc.wait()
async def backtest_sleep(secs):
"""An async sleep function for use during backtesting."""
config = Config()
btc = config.backtest_controller
sleep = config.backtest_engine.cursor.time + secs
while sleep > config.backtest_engine.cursor.time:
btc.wait()


class Session:
Expand Down
15 changes: 8 additions & 7 deletions src/aiomql/lib/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ async def delay(self, *, secs: float):

async def _backtest_sleep(self, *, secs: float):
try:
if self.backtest_controller.parties == 2:
steps = int(secs) // self.config.backtest_engine.speed
steps = max(steps, 1)
self.config.backtest_engine.fast_forward(steps=steps)
self.backtest_controller.wait()

elif self.backtest_controller.parties > 2:
# if self.backtest_controller.parties == 2:
# this is not needed, as the backtest_engine iterator will handle this
# steps = int(secs) // self.config.backtest_engine.speed
# steps = max(steps, 1)
# self.config.backtest_engine.fast_forward(steps=steps)
# self.backtest_controller.wait()

if self.backtest_controller.parties >= 2:
_time = self.config.backtest_engine.cursor.time + secs
while _time > self.config.backtest_engine.cursor.time:
self.backtest_controller.wait()
Expand Down

0 comments on commit 8a4f5fe

Please sign in to comment.