tdxdata 0.2.9__tar.gz → 0.2.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {tdxdata-0.2.9/src/tdxdata.egg-info → tdxdata-0.2.10}/PKG-INFO +1 -1
  2. {tdxdata-0.2.9 → tdxdata-0.2.10}/pyproject.toml +1 -1
  3. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/__init__.py +1 -1
  4. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/commands/finance.py +2 -1
  5. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/commands/xdxr.py +12 -20
  6. {tdxdata-0.2.9 → tdxdata-0.2.10/src/tdxdata.egg-info}/PKG-INFO +1 -1
  7. {tdxdata-0.2.9 → tdxdata-0.2.10}/tests/test_xdxr.py +23 -1
  8. {tdxdata-0.2.9 → tdxdata-0.2.10}/LICENSE +0 -0
  9. {tdxdata-0.2.9 → tdxdata-0.2.10}/NOTICE.md +0 -0
  10. {tdxdata-0.2.9 → tdxdata-0.2.10}/README.md +0 -0
  11. {tdxdata-0.2.9 → tdxdata-0.2.10}/setup.cfg +0 -0
  12. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/adjust.py +0 -0
  13. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/cli.py +0 -0
  14. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/cli_qx.py +0 -0
  15. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/client.py +0 -0
  16. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/commands/__init__.py +0 -0
  17. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/commands/auth.py +0 -0
  18. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/commands/bars.py +0 -0
  19. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/commands/quotes.py +0 -0
  20. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/frame.py +0 -0
  21. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/gbbq.py +0 -0
  22. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/gbbq_keys.py +0 -0
  23. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/pool2.py +0 -0
  24. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/protocol.py +0 -0
  25. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata/servers.txt +0 -0
  26. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata.egg-info/SOURCES.txt +0 -0
  27. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata.egg-info/dependency_links.txt +0 -0
  28. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata.egg-info/entry_points.txt +0 -0
  29. {tdxdata-0.2.9 → tdxdata-0.2.10}/src/tdxdata.egg-info/top_level.txt +0 -0
  30. {tdxdata-0.2.9 → tdxdata-0.2.10}/tests/test_adjust.py +0 -0
  31. {tdxdata-0.2.9 → tdxdata-0.2.10}/tests/test_finance_pool.py +0 -0
  32. {tdxdata-0.2.9 → tdxdata-0.2.10}/tests/test_gbbq.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tdxdata
3
- Version: 0.2.9
3
+ Version: 0.2.10
4
4
  Summary: TDX (通达信) 2026-09 新版行情协议客户端 — realtime A-share quotes
5
5
  Author: tdxdata contributors
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tdxdata"
7
- version = "0.2.9"
7
+ version = "0.2.10"
8
8
  description = "TDX (通达信) 2026-09 新版行情协议客户端 — realtime A-share quotes"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -28,7 +28,7 @@ from .gbbq import (GBBQ_URL, decrypt_record, decrypt_records,
28
28
  download_gbbq, events_of, read_gbbq, to_map)
29
29
  from .pool2 import Pool # 0.2.0: 顶层导出并发池(含 finance_all),否则 import tdxdata; tdxdata.Pool 不可见
30
30
 
31
- __version__ = "0.2.9" # ponytail: 与 pyproject.toml 手工同步;tests 里有漂移断言兜底
31
+ __version__ = "0.2.10" # ponytail: 与 pyproject.toml 手工同步;tests 里有漂移断言兜底
32
32
  __all__ = ["TdxClient", "Pool", "market_of", "parse_snap", "__version__",
33
33
  # 权息 / 复权(2026-11-13 新增)
34
34
  "GBBQ_URL", "download_gbbq", "read_gbbq", "decrypt_record", "decrypt_records",
@@ -4,7 +4,8 @@
4
4
  请求 21B: 0c1f 1876 0001 0b00 0b00 1000 0100 + market + code6
5
5
  响应: 帧头 + count(2) + market(1) + code(6) + 流通股本(f32) + 省份(u16) + 行业(u16)
6
6
  + 更新日期(u32 yyyymmdd) + IPO(u32) + 总股本..每股净资产(28×f32)
7
- 单位: 股本=万股(×10000→股); 金额=千元(×1000→元); 股东人数/每股净资产=直接值
7
+ 单位(**返回值**): 股本=**股**(线上字段是万股,函数内已 ×10000);
8
+ 金额=**元**(线上字段是千元,已 ×1000); 股东人数/每股净资产=直接值
8
9
  ⚠️ pytdx 把金额类按万元×10000(放大10倍,其 docstring 平安总资产 30 万亿即此 bug),本实现已修正
9
10
  """
10
11
  import struct
@@ -7,7 +7,7 @@
7
7
  - category == 1(除权除息): 4 × float32 LE = 分红(每10股派n元) / 配股价 / 送转(每10股) / 配股(每10股)
8
8
  - category 11/12(缩股): 第 3 个 float32 为缩股比例
9
9
  - category 13/14(送权证): 第 1、3 个 float32 有效
10
- - 其他: 4 × uint32 股本(万股,通达信自研 volume 编码)
10
+ - 其他(股本变化/增发等): 4 × float32 = 股本(万股)——前流通/前总/后流通/后总
11
11
 
12
12
  与客户端本地 `gbbq` 文件的记录**格式完全一致**(同 29B 布局),实测 001225 / 001285 /
13
13
  001309 / 600519 四只与本地 gbbq 逐条一致(2026-11-13)。
@@ -29,17 +29,6 @@ CATEGORY_NAMES = {
29
29
  }
30
30
 
31
31
 
32
- def _get_volume(v: int) -> float:
33
- """通达信自研 4 字节浮点(成交量/股本编码),来自 pytdx 的 get_volume 口径"""
34
- ivol = v
35
- logpoint = (ivol >> 24) & 0xFF
36
- hleax = (ivol >> 16) & 0xFF
37
- lheax = (ivol >> 8) & 0xFF
38
- lleax = ivol & 0xFF
39
- d1 = hleax + lheax / 256.0 + lleax / 65536.0
40
- return d1 * pow(2, logpoint - 127) * 100.0
41
-
42
-
43
32
  def build_xdxr_req(market: int, code: str, msg_id: int = 0) -> bytes:
44
33
  """构造除权除息请求帧(market: 0=深 1=沪)"""
45
34
  data = bytes([0x01, 0x00, market]) + code.encode()
@@ -76,18 +65,21 @@ def parse_xdxr(body: bytes) -> list:
76
65
  'peigu': 0.0, # 配股(每10股)
77
66
  'shares': None, # 股本类类别才有:前流通/前总/后流通/后总(万股)
78
67
  }
68
+ # ⚠️ 4 个字段一律 float32(2026-11-13 实测更正):与 gbbq 文件同一编码;
69
+ # 早期版本误按「uint32 + 自研 volume 解码」处理非除权除息类 → 股本恒为 0.0(0.2.6~0.2.9 的 bug)。
70
+ # 实测对照:301233 20261112 cat=5 → (3937.61, 7176.68, 3937.61, 7231.82) 万股,
71
+ # 与同股实时 finance 流通A股(39,376,101 股 = 3937.61 万股)一致。
72
+ f1, f2, f3, f4 = struct.unpack_from('<ffff', bs, 13)
79
73
  if cat == 1:
80
- fh, pgj, szg, pg = struct.unpack_from('<ffff', bs, 13)
81
- rec.update(fenhong=round(fh, 6), peigujia=round(pgj, 6),
82
- songzhuangu=round(szg, 6), peigu=round(pg, 6))
74
+ rec.update(fenhong=round(f1, 6), peigujia=round(f2, 6),
75
+ songzhuangu=round(f3, 6), peigu=round(f4, 6))
83
76
  elif cat in (11, 12):
84
- rec['songzhuangu'] = round(struct.unpack_from('<f', bs, 21)[0], 6) # 缩股比例
77
+ rec['songzhuangu'] = round(f3, 6) # 缩股比例
85
78
  elif cat in (13, 14):
86
- rec['peigujia'] = round(struct.unpack_from('<f', bs, 13)[0], 6) # 行权价
87
- rec['peigu'] = round(struct.unpack_from('<f', bs, 21)[0], 6) # 份数
79
+ rec['peigujia'] = round(f1, 6) # 行权价
80
+ rec['peigu'] = round(f3, 6) # 份数
88
81
  else:
89
- v = [struct.unpack_from('<I', bs, 13 + 4 * i)[0] for i in range(4)]
90
- rec['shares'] = tuple(round(_get_volume(x) * 1e4, 2) for x in v)
82
+ rec['shares'] = (round(f1, 6), round(f2, 6), round(f3, 6), round(f4, 6))
91
83
  out.append(rec)
92
84
  bs = bs[29:]
93
85
  return out
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tdxdata
3
- Version: 0.2.9
3
+ Version: 0.2.10
4
4
  Summary: TDX (通达信) 2026-09 新版行情协议客户端 — realtime A-share quotes
5
5
  Author: tdxdata contributors
6
6
  License: MIT License
@@ -59,8 +59,30 @@ def test_parse_edge_cases():
59
59
  assert xdxr_of(b'\x00' * 20, 1) == []
60
60
 
61
61
 
62
+ # 301233 2026-11-12 category=5(股本变化)实录记录 —— 锁死「股本 = 4 × float32(万股)」解码
63
+ # 早期版本误按 uint32+自研 volume 解码 → 股本恒为 0.0(0.2.6~0.2.9 的 bug)
64
+ SHARES_FIXTURE = '0033303132333300f828350105d21976457145e045d21976458ffee145'
65
+
66
+
67
+ def test_shares_field_float32():
68
+ import struct
69
+ rec = bytes.fromhex(SHARES_FIXTURE)
70
+ body = b'\x00' * 9 + struct.pack('<H', 1) + rec
71
+ r = parse_xdxr(body)[0]
72
+ assert r['code'] == '301233' and r['date'] == 20261112
73
+ assert r['category'] == 5 and r['category_name'] == '股本变化'
74
+ shares = r['shares']
75
+ assert shares is not None, '股本类记录必须给出 shares'
76
+ # 万股:前流通 / 前总 / 后流通 / 后总
77
+ assert abs(shares[0] - 3937.61) < 0.01, shares
78
+ assert abs(shares[1] - 7176.68) < 0.01, shares
79
+ assert abs(shares[3] - 7231.82) < 0.01, shares
80
+ assert all(v > 0 for v in shares), f'不能是 0(旧 bug 症状): {shares}'
81
+
82
+
62
83
  if __name__ == '__main__':
63
84
  test_build_req_shape()
64
85
  test_parse_from_fixture()
65
86
  test_parse_edge_cases()
66
- print('test_xdxr: 全部通过 ✅')
87
+ test_shares_field_float32()
88
+ print('test_xdxr: 全部通过 ✅')
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes