mirror of
https://github.com/Ichinga-Samuel/aiomql.git
synced 2026-07-27 20:27:43 +00:00
Merge branch 'main' into dev
This commit is contained in:
+1
-1
@@ -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 = [
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from .core import *
|
||||
from .lib import *
|
||||
from .contrib import *
|
||||
from ._utils import *
|
||||
|
||||
+22
-24
@@ -10,35 +10,33 @@ from .core.config import Config
|
||||
|
||||
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)
|
||||
sleep = config.backtest_engine.cursor.time + secs
|
||||
while sleep > config.backtest_engine.cursor.time:
|
||||
await asyncio.sleep(0)
|
||||
|
||||
|
||||
# async def backtest_sleep(secs):
|
||||
# """An async sleep function for use during backtesting."""
|
||||
# btc = BackTestController()
|
||||
# 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:
|
||||
|
||||
@@ -6,7 +6,6 @@ from logging import getLogger
|
||||
from ..core.models import OrderSendResult, TradePosition
|
||||
from ..core.config import Config
|
||||
from .positions import Positions
|
||||
from .._utils import backtest_sleep
|
||||
|
||||
logger = getLogger(__name__)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -126,13 +126,14 @@ class Strategy(ABC):
|
||||
|
||||
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()
|
||||
# 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()
|
||||
|
||||
elif self.backtest_controller.parties > 2:
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user