Skip to content

bug(portfolio): 空头持仓的盈亏金额与百分比方向相反 #397

Description

@brad0810wz-rgb

最新main f5822f0,quantity=-10、cost100、market120,经真实parsePortfolioResponse→portfolio.summary capability→HoldingRow,金额为-$200,但百分比+20%;price80时金额+$200、百分比-20%。碎股空头也相同。

normalizer的computed percent只看价格涨跌,未看数量方向。Longbridge官方文档确认负数量为空头:https://open.longbridge.com/docs/trade/order/close_position 。当前helper唯一生产调用为normalizeHolding,输入先经finite guard;该路径没有读取provider已报告ratio,所以本修复无需反转任何已报告百分比。

预期:仅本地computed percent按空头方向计算;两参数旧调用、正数/零/缺失数量及flat零值兼容;金额、市值和权重语义不扩范围。已用真实组件显示复现并完成全状态Issue/PR查重,无同类。

新回归在原生产代码20pass/1skip/6fail;拟修复后相关161pass/7skip/0fail,真实parser/capability/显示证据将随PR提供。

Activity

  1. xxstar-01 commented on Nov 7, 2026

    @xxstar-01
    Contributor

    /claim

    我来处理 #397。

    范围:只改 packages/longbridge-tools/src/normalizer.ts 的 computeUnrealizedPnLPercent,让它接收可选的 quantity 并按空头方向取符号,使百分比与 computeUnrealizedPnL 的金额同号;两参数旧调用、正数/零/缺失数量保持原行为。不动金额、市值与权重语义。

    验证计划:在 normalizer.test.ts 补空头正反两向与兼容性用例,并跑 bun test --isolate 与 bun run typecheck。

  2. added
    claimedClaimed by a contributor and currently in progress
    on Nov 7, 2026
  3. github-actions commented on Nov 7, 2026

    @github-actions

    @xxstar-01 已认领该 Issue,并已自动设为 Assignee。提交 PR 时请在描述中写 Closes #397。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

claimedClaimed by a contributor and currently in progress

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions