fix(live): 恒等式逐票对账补负向幻影——09-04 收盘联检实证:002633买缺100(正向孤儿,已列)+002836卖缺300(负向幻影,漏列),旧代码unattr_positions只遍历snap_pos.items(),快照没有的票永不被遍历到,单看票单会把修账做成半拉子(只补孤儿不补幻影);修=双端键并集sorted(set(snap_pos)|set(inst_pos)),正向孤儿/负向幻影都入列(002836当日在报告里只有MV差对不上数才现形);残差拆腿同步定性:-1535=100×002633收盘15.35-300×002836收盘10.23,100%来自两笔引擎未报成交,修账后应归零;TDD 1新测先红后绿+21全过 [vps]
CI/CD / test (push) Successful in 1s
CI/CD / nas-deploy (push) Successful in 14s
CI/CD / nas-verify (push) Successful in 18s

This commit is contained in:
2026-09-04 18:29:07 +08:00
parent e2902cdf1f
commit 6adb40e7a0
2 changed files with 23 additions and 4 deletions
@@ -380,6 +380,23 @@ def test_identity_unattributed_position_listed(db):
assert r["identity_passed"] is False
def test_identity_phantom_position_listed(db):
"""实例账本有快照没有的票(幻影仓,如卖出迟到未记账)→ 负差票单列(09-04 002836 实证)。"""
_add_live_account(db, aid=5)
_seed_snapshot(db, mv=1_000_000, positions=[
{"symbol": "600036.SH", "volume": 1000, "can_use": 1000,
"avg_price": 38, "mv": 38000}])
_seed_inst_mv(db, 5, mv=997_000,
positions={"600036.XSHG": 1000, "002836.XSHE": 300}) # 幻影 300 股
r = build_identity_report(db)
row = r["rows"][0]
unattr = row["unattributed_positions"]
assert [p["symbol"] for p in unattr] == ["002836"]
assert unattr[0]["snapshot_volume"] == 0
assert unattr[0]["instance_volume"] == 300
assert unattr[0]["diff"] == -300
def test_identity_instance_over_snapshot_negative(db):
"""Σ实例>快照(旧全账户行叠加期)→ 未归因为负,如实呈现 FAIL。"""
_add_live_account(db, aid=5)