merge: integrate alpha management with main and sequence migration 0005

This commit is contained in:
yuxuanhui
2026-09-08 10:45:00 +08:00
56 changed files with 7453 additions and 55 deletions
+12
View File
@@ -44,6 +44,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:
@@ -54,6 +57,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
@@ -62,6 +66,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):
@@ -77,6 +82,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)
@@ -249,6 +255,10 @@ class Runner:
await self.ensure_connected(force=kind == "connect")
if kind in ("connect", "profile"):
await self.refresh_profile()
elif kind in ("catalog_sync", "field_sync"):
from .catalog.sync import sync_catalog
await sync_catalog(self, job_id, payload)
elif kind in ("full_sync", "daily_sync"):
await self.sync_all(job_id)
else:
@@ -366,6 +376,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"])):
@@ -441,6 +452,7 @@ class Runner:
else:
await self.save_pnl(db, alpha_id, raw, points)
else:
await db.scalar(select(Account).where(Account.id == 1).with_for_update())
await upsert_alpha(db, raw)
previous.error = error
if error: