缓存看股数据
This commit is contained in:
@@ -107,6 +107,8 @@ def _rows_to_bars(rows) -> list[Bar]:
|
||||
|
||||
|
||||
_ADJUST_MODES = ("bfq", "qfq", "hfq")
|
||||
# MA 全量集合(前端已改为本地计算 MA,后端始终返回此集合以保证缓存一致)
|
||||
_FULL_MA_SET = (5, 10, 20, 30, 60, 120, 250)
|
||||
|
||||
|
||||
def _adjust_bars(bars: list[Bar], factors, from_mode: str, to_mode: str) -> list[Bar]:
|
||||
@@ -814,10 +816,11 @@ async def screener_preview(
|
||||
symbol = plain_code(ts_code)
|
||||
|
||||
# --- Redis 读缓存:历史窗口(end 翻页)只增不改,最新窗口每日由全市场同步推进;
|
||||
# 键含 ver:candles 版本号(同步完成后自增,旧缓存全部失效),TTL 兜底(cache.py)---
|
||||
# 键含 ver:candles 版本号(同步完成后自增,旧缓存全部失效),TTL 兜底(cache.py)
|
||||
# 注:ma_periods 不参与缓存键 —— 前端已改为本地计算 MA,后端始终返回全量 MA 集合
|
||||
cache_key = cache.digest(
|
||||
"preview", ts_code, timeframe, limit, adjust,
|
||||
end_dt.strftime("%Y-%m-%d") if end_dt else None, ma_periods, zx_periods,
|
||||
end_dt.strftime("%Y-%m-%d") if end_dt else None,
|
||||
await cache.get_version("candles"),
|
||||
)
|
||||
cached = await cache.cache_get(f"pv:{cache_key}")
|
||||
@@ -896,7 +899,8 @@ async def screener_preview(
|
||||
kdj = ind.kdj(highs, lows, closes)
|
||||
boll = ind.bollinger(closes)
|
||||
indicators = {
|
||||
"ma": {f"ma{p}": _series_to_jsonable(ind.ma(closes, p)) for p in ma_periods},
|
||||
# MA 始终返回全量集合(前端本地计算 MA,此处仅保留兼容;缓存键不依赖 ma_periods)
|
||||
"ma": {f"ma{p}": _series_to_jsonable(ind.ma(closes, p)) for p in _FULL_MA_SET},
|
||||
"macd": {
|
||||
"dif": _series_to_jsonable(macd["macd"]),
|
||||
"dea": _series_to_jsonable(macd["signal"]),
|
||||
|
||||
Reference in New Issue
Block a user