This commit is contained in:
2026-09-05 00:12:19 +08:00
parent 991d1bf343
commit ad9245abdd
12 changed files with 287 additions and 595 deletions

View File

@@ -66,32 +66,3 @@ def fetch_daily(code: str, start: str = "20200101", end: str | None = None,
)
)
return bars
def fetch_chips(ts_code: str, end: str | None = None):
"""拉取筹码分布截面cyq_perf成本分位/获利比例/平均成本)+ cyq_chips价位→占比
end 为 YYYYMMDD 参考日:取 <=end 的最近有数据交易日(周/月 K 线由前端换算成
周期末传入这里只需向前吸附到实际数据日None 取最新。
数据自 2018 年起,早于此返回 (None, [])。返回 (perf_dict|None, [(price, percent)])。
"""
from datetime import timedelta
pro = get_pro()
e = end or datetime.now().strftime("%Y%m%d")
if e < "20180101":
return None, []
# 吸附余量 60 个自然日:覆盖春节等长假 + 月初参考日(如月 K 传上月末)
s = (datetime.strptime(e, "%Y%m%d") - timedelta(days=60)).strftime("%Y%m%d")
s = max(s, "20180101")
perf = pro.cyq_perf(ts_code=ts_code, start_date=s, end_date=e)
if perf is None or perf.empty:
return None, []
perf = perf.sort_values("trade_date").iloc[-1] # <=end 的最近一条
d = str(perf["trade_date"])
chips = pro.cyq_chips(ts_code=ts_code, trade_date=d)
rows: list[tuple[float, float]] = []
if chips is not None and not chips.empty:
rows = [(float(p), float(v)) for p, v in zip(chips["price"], chips["percent"])]
return perf.to_dict(), rows