feat: add durable WorldQuant backtests with UI and AI confirmation
This commit is contained in:
@@ -43,6 +43,9 @@ class Runner:
|
||||
self.control_lock = asyncio.Lock()
|
||||
self.recover_database = False
|
||||
self.wake = asyncio.Event()
|
||||
from .backtests.runtime import BacktestLane
|
||||
|
||||
self.backtests = BacktestLane(self)
|
||||
|
||||
async def start(self):
|
||||
async with self.sessions() as db:
|
||||
@@ -53,6 +56,7 @@ class Runner:
|
||||
account.verification_url = None
|
||||
await db.commit()
|
||||
self.loop_task = asyncio.create_task(self.run_loop())
|
||||
await self.backtests.start()
|
||||
|
||||
async def stop(self):
|
||||
self.stopping = True
|
||||
@@ -61,6 +65,7 @@ class Runner:
|
||||
self.active_task.cancel()
|
||||
if self.loop_task:
|
||||
await self.loop_task
|
||||
await self.backtests.stop()
|
||||
await self.client.close()
|
||||
|
||||
async def cancel(self, job_id):
|
||||
@@ -76,6 +81,7 @@ class Runner:
|
||||
try:
|
||||
if self.active_task:
|
||||
await self.cancel(self.active_id)
|
||||
await self.backtests.interrupt()
|
||||
self.client.disconnect()
|
||||
async with self.sessions() as db:
|
||||
account = await db.get(Account, 1)
|
||||
@@ -319,6 +325,7 @@ class Runner:
|
||||
job = await db.get(Job, job_id)
|
||||
if job.cancel_requested:
|
||||
raise asyncio.CancelledError()
|
||||
await db.scalar(select(Account).where(Account.id == 1).with_for_update())
|
||||
for raw_alpha in rows:
|
||||
await upsert_alpha(db, raw_alpha)
|
||||
if not await db.get(JobItem, (job_id, raw_alpha["id"])):
|
||||
@@ -395,6 +402,7 @@ class Runner:
|
||||
db.add(pnl)
|
||||
pnl.raw, pnl.points, pnl.fetched_at = sanitize(raw), points, now()
|
||||
else:
|
||||
await db.scalar(select(Account).where(Account.id == 1).with_for_update())
|
||||
await upsert_alpha(db, raw)
|
||||
previous.error = error
|
||||
if error:
|
||||
|
||||
Reference in New Issue
Block a user