"""协议底层修复验证(针对 2026-04-15 审查结论)。""" import struct from unittest.mock import patch from easy_tdx.codec.price_rules import compute_price_limits from easy_tdx.commands.fund_flow import GetHistoryFundFlowCmd from easy_tdx.commands.security_bars import GetSecurityBarsCmd from easy_tdx.commands.security_list import GetSecurityListCmd from easy_tdx.commands.security_quotes import GetSecurityQuotesCmd from easy_tdx.models.enums import KlineCategory, Market def test_security_bars_exact_layout(): """验证 K 线请求包布局与旧版 working bytes 完全一致。""" cmd = GetSecurityBarsCmd(Market.SH, "600000", KlineCategory.DAY, 0, 10) req = cmd.build_request() # Header: 0x010C, 0x01016408, 0x1C, 0x1C # Payload: 0x052D, 1 (Market.SH), "600000", 4 (KlineCategory.DAY), 1, 0 (start), 10, 0, 0, 0 expected = struct.pack( " float: seen.append(raw) return float(raw) with patch("easy_tdx.commands.fund_flow._decode_volume", side_effect=fake_decode): records = GetHistoryFundFlowCmd(Market.SH, "600000", 0, 1).parse_response(bytes(body)) assert seen == raw_words assert records[0].small_out == float(raw_words[-1])