fix: K线响应截断容错 + 一键寻优并发默认8进程

- security_bars: parse_response 遇末尾残缺记录时丢弃并返回前 N-1 条,
  避免 TDX 服务端截断响应导致整页 500(如 000408 count=800 日线)
- OptimizeView: 一键寻优并发默认 8 进程,用户选择持久化到 localStorage

bump version to 1.18.3
This commit is contained in:
GitHub
2026-07-06 13:23:37 +08:00
parent c901d198ca
commit e3e8dd492e
5 changed files with 127 additions and 23 deletions
+36
View File
@@ -10,6 +10,8 @@ from __future__ import annotations
import pathlib
import struct
import pytest
FIXTURES = pathlib.Path(__file__).parent.parent / "fixtures"
@@ -125,6 +127,40 @@ def test_security_bars_parse():
assert len(bar._raw) > 0
def test_security_bars_truncated_drops_partial_last_record():
"""TDX 服务端偶发截断:响应头声称有 N 条,但末尾记录被切。
解析器应丢弃残缺的末条,返回已成功解析的前若干条,而非整体抛 500。
"""
from easy_tdx.commands.security_bars import GetSecurityBarsCmd
from easy_tdx.models.enums import KlineCategory, Market
body = load_hex("security_bars") # 完整 5 条
# 把最后一条的 body 切掉 3 字节 → 末条 zipday 4 字节不够,触发截断
truncated = body[:-3]
cmd = GetSecurityBarsCmd(Market.SH, "600000", KlineCategory.DAY, 0, 5)
bars = cmd.parse_response(truncated)
assert len(bars) == 4 # 前 4 条完整,末条残缺被丢弃
def test_security_bars_truncated_first_record_still_raises():
"""若连第一条都无法解析(body 完全没有记录数据),仍抛 TdxDecodeError。"""
from easy_tdx.commands.security_bars import GetSecurityBarsCmd
from easy_tdx.exceptions import TdxDecodeError
from easy_tdx.models.enums import KlineCategory, Market
body = load_hex("security_bars")
# 构造 header 声称 5 条但 body 只有 header(2 字节)+1 字节 → 第一条就截断
truncated = body[:3]
# 强行把 ret_count 写成 5
truncated = struct.pack("<H", 5) + truncated[2:]
cmd = GetSecurityBarsCmd(Market.SH, "600000", KlineCategory.DAY, 0, 5)
with pytest.raises(TdxDecodeError):
cmd.parse_response(truncated)
# ---------------------------------------------------------------------------
# security_quotes
# ---------------------------------------------------------------------------