Fix security list pre-close decoding

This commit is contained in:
minionszyw
2026-04-22 18:50:07 +08:00
parent 41cb3bfd28
commit 91f6a884d5
5 changed files with 35 additions and 11 deletions
+2 -2
View File
@@ -3,6 +3,6 @@
"first": {
"code": "999999",
"name": "上证指数",
"pre_close": 11654847.33
"pre_close": 3966.171142578125
}
}
}
+27 -2
View File
@@ -7,6 +7,7 @@ fixtures/ 目录下每个 .hex 文件是一次真实服务器响应的 body(
from __future__ import annotations
import pathlib
import struct
FIXTURES = pathlib.Path(__file__).parent.parent / "fixtures"
@@ -50,13 +51,37 @@ def test_security_list_parse():
r0 = records[0]
assert r0.code == "999999"
assert r0.name == "上证指数"
# pre_close is a float; the index level is stored ×100 and has many decimal places
assert abs(r0.pre_close - 11654847.33) < 1.0
assert abs(r0.pre_close - 3966.171142578125) < 0.01
# _raw present and non-empty for every record
assert all(len(r._raw) > 0 for r in records)
def test_security_list_pre_close_uses_tdx_float_for_a_share():
from xmtdx.commands.security_list import GetSecurityListCmd
from xmtdx.models.enums import Market
body = (
struct.pack("<H", 1)
+ struct.pack(
"<6sH8s4sBI4s",
b"600000",
100,
"\u6d66\u53d1\u94f6\u884c".encode("gbk"),
b"\x00\x00\x00\x00",
2,
0x411B851F,
b"\x00\x00\x00\x00",
)
)
record = GetSecurityListCmd(Market.SH, 24000).parse_response(body)[0]
assert record.code == "600000"
assert record.name == "浦发银行"
assert abs(record.pre_close - 9.72) < 0.01
def test_security_list_gbk_no_crash():
"""Bug #2 修复验证:GBK 解码不崩溃,所有记录均有 code。"""
from xmtdx.commands.security_list import GetSecurityListCmd