fix(offline): sync-daily 成交量单位换算(股→手),修复大盘股 uint32 溢出 (#60)

encode_daily_bar 按 vol/vol_coeff(vol_coeff=0.01 时 ×100)写入 .day,
期望输入为手;而 K 线协议返回的成交量单位是股。原 _sync_one_daily 直接把
股喂给 append_daily_bars,日成交 >4295 万股的股票(招商银行等)编码后
溢出 uint32,struct.pack('I') 报错,sync-daily/sync-all 失败。

在 vol_coeff == 0.01 的证券类型写入前换算 股→手(读取端 ×0.01 还原,
方向对称)。用服务器原生 .day 文件实测验证:浦发银行 2026-08-31 原始
vol 字段 99,682,464 与协议 API(股)完全一致。

Co-authored-by: awayings <awayings@qq.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Jason Zhang
2026-08-31 20:28:15 +08:00
committed by GitHub
co-authored by awayings Claude
parent a7b14d3388
commit ac512d791c
+7
View File
@@ -557,6 +557,13 @@ def _sync_one_daily(client: TdxClient, filepath: Path) -> tuple[int, str]:
sec_type = _detect_security_type(filepath.name)
price_coeff, vol_coeff = _SECURITY_COEFFICIENTS.get(sec_type, (0.01, 0.01))
# 协议返回的成交量单位是股;encode_daily_bar 在 vol_coeff=0.01 时按 ×100
# 写入(.day 原始字段为股,读取端 ×0.01 还原为手),故写入前须换算为手。
# 否则日成交 > 4295 万股(如招商银行等大盘股)的 bar 会溢出 uint32。
if vol_coeff == 0.01:
for b in bars:
b.vol /= 100
# 追加写入
written = append_daily_bars(filepath, bars, price_coeff, vol_coeff)
if written > 0: