first commit

This commit is contained in:
2026-08-07 16:08:34 +08:00
commit e0b5228008
51 changed files with 5175 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
"""K 线数据访问(从库读)。
写入由 DataProvider 适配器负责阶段1 接 Tushare/AKShare
MVP 的数据由 synthetic.seed_if_empty 灌入。
"""
from __future__ import annotations
from datetime import datetime
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from ..models import Candle
async def get_candles(
session: AsyncSession,
symbol: str,
timeframe: str = "1d",
start: datetime | None = None,
end: datetime | None = None,
limit: int = 5000,
) -> list[Candle]:
stmt = select(Candle).where(
Candle.symbol == symbol,
Candle.timeframe == timeframe,
)
if start is not None:
stmt = stmt.where(Candle.ts >= start)
if end is not None:
stmt = stmt.where(Candle.ts <= end)
stmt = stmt.order_by(Candle.ts.asc()).limit(limit)
result = await session.execute(stmt)
return list(result.scalars().all())