fix: support legacy research snapshots on macOS

This commit is contained in:
2026-08-05 10:40:45 +02:00
parent e58d2bb2cf
commit 477aa4b2da
3 changed files with 147 additions and 7 deletions
+44 -5
View File
@@ -210,6 +210,43 @@ def _worker_run_cell(cell: dict[str, Any]) -> dict[str, Any]:
}
async def _fetch_snapshot_columns(
db: AsyncSession,
ticker_id: int,
) -> tuple | None:
'''Load only the stable OHLCV columns required by the research replay.
Research snapshots can predate unrelated additions to the Ticker ORM model
(for example SEC CIK/SIC metadata). Keeping this query column-scoped avoids
requiring or mutating those newer application-schema fields.
'''
from app.models.ohlcv import OHLCVRecord
result = await db.execute(
select(
OHLCVRecord.date,
OHLCVRecord.open,
OHLCVRecord.high,
OHLCVRecord.low,
OHLCVRecord.close,
OHLCVRecord.volume,
)
.where(OHLCVRecord.ticker_id == ticker_id)
.order_by(OHLCVRecord.date)
)
rows = result.all()
if not rows:
return None
return (
[row[0].toordinal() for row in rows],
[float(row[1]) for row in rows],
[float(row[2]) for row in rows],
[float(row[3]) for row in rows],
[float(row[4]) for row in rows],
[int(row[5]) for row in rows],
)
async def _load_snapshot(
snapshot: Path,
*,
@@ -238,14 +275,16 @@ async def _load_snapshot(
refresh=False,
)
ticker_result = await db.execute(
select(Ticker).order_by(Ticker.symbol)
select(Ticker.id, Ticker.symbol).order_by(Ticker.symbol)
)
symbols = [
ticker.symbol for ticker in ticker_result.scalars().all()
ticker_rows = [
(int(ticker_id), str(symbol))
for ticker_id, symbol in ticker_result.all()
]
symbols = [symbol for _ticker_id, symbol in ticker_rows]
prices: dict[str, tuple] = {}
for index, symbol in enumerate(symbols, 1):
columns = await bt._fetch_columns(db, symbol)
for index, (ticker_id, symbol) in enumerate(ticker_rows, 1):
columns = await _fetch_snapshot_columns(db, ticker_id)
if columns is not None:
prices[symbol] = columns
if not quiet and index % 50 == 0: