mirror of
https://ghfast.top/https://github.com/aeroxw/easy-tdx.git
synced 2026-09-12 20:24:16 +08:00
- Package directory: src/xmtdx/ -> src/easy_tdx/ - Import path: from easy_tdx import ... - pip install easy-tdx - Add LICENSE (MIT) with upstream attribution (pytdx, xmtdx) - Add NOTICE with detailed attribution - Update all examples, tests, scripts, docs - Bump version to 1.0.0 BREAKING CHANGE: import path changed from `xmtdx` to `easy_tdx` Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""get_volume 单元测试,测试向量来自 pytdx 注释中的已知值。"""
|
|
|
|
import struct
|
|
|
|
from easy_tdx.codec.volume import get_volume
|
|
|
|
|
|
def _pack(ivol: int) -> bytes:
|
|
return struct.pack("<I", ivol)
|
|
|
|
|
|
class TestGetVolume:
|
|
def test_zero(self):
|
|
val, pos = get_volume(_pack(0), 0)
|
|
assert val == 0.0
|
|
assert pos == 4
|
|
|
|
def test_known_value_4098(self):
|
|
# pytdx 注释 "4098 ---> 3.0" 含义:raw 4098 对应真实股数 3.0亿,
|
|
# 但 get_volume(4098) ≈ 5.88e-39(接近零),说明 xdxr_info 里对股本字段
|
|
# 调用 get_volume 是错误用法。easy-tdx 在 xdxr_info 命令中会用正确的解码方式。
|
|
val, pos = get_volume(_pack(4098), 0)
|
|
assert abs(val) < 1e-30 # 接近零,与 pytdx 行为一致
|
|
|
|
def test_advances_pos(self):
|
|
data = _pack(0) + _pack(0)
|
|
_, pos = get_volume(data, 0)
|
|
assert pos == 4
|
|
_, pos2 = get_volume(data, pos)
|
|
assert pos2 == 8
|
|
|
|
def test_nonnegative(self):
|
|
# 成交量不应为负
|
|
for raw in [0, 1000, 0x10000, 0x1000000, 0x7FFFFFFF]:
|
|
val, _ = get_volume(_pack(raw), 0)
|
|
assert val >= 0.0
|