看股功能更新

This commit is contained in:
2026-08-15 15:36:11 +08:00
parent c1c43d2ff7
commit 9cce670b74
26 changed files with 957 additions and 427 deletions

View File

@@ -32,3 +32,38 @@ async def get_candles(
stmt = stmt.order_by(Candle.ts.asc()).limit(limit)
result = await session.execute(stmt)
return list(result.scalars().all())
async def get_recent_candles(
session: AsyncSession,
symbol: str,
timeframe: str = "1d",
limit: int = 5000,
) -> list[Candle]:
"""取最近 limit 根 K 线(含最新交易日),按时间升序返回。"""
stmt = (
select(Candle)
.where(Candle.symbol == symbol, Candle.timeframe == timeframe)
.order_by(Candle.ts.desc())
.limit(limit)
)
result = await session.execute(stmt)
return list(reversed(result.scalars().all()))
async def get_candles_before(
session: AsyncSession,
symbol: str,
timeframe: str,
before: datetime,
limit: int = 5000,
) -> list[Candle]:
"""取 before 之前(不含)的最近 limit 根 K 线,按时间升序返回(历史向前翻页用)。"""
stmt = (
select(Candle)
.where(Candle.symbol == symbol, Candle.timeframe == timeframe, Candle.ts < before)
.order_by(Candle.ts.desc())
.limit(limit)
)
result = await session.execute(stmt)
return list(reversed(result.scalars().all()))