test(fe): 添加部分平仓比例刷新守卫 + 历史对账骨架(离线无DB) — closePercentInterestRefresh 守卫全部→部分平仓比例刷新链; historicalReconciliation 独立规格vs落库值差分; 全部18套件276测试通过

This commit is contained in:
hjhan
2026-08-08 14:16:54 +08:00
parent 096d2609eb
commit fc01b766cd
5 changed files with 687 additions and 0 deletions
@@ -0,0 +1,85 @@
{
"meta": {
"schemaVersion": 1,
"source": "hand-crafted representative samples (replace/extend via tools/exportHistoricalSwapEvents.js against real DB)",
"note": "每条 record 的 inputs 是前端 calcCloseAmount 实际会收到的形态(deal/floatPosition/interestList/marginList)expected 是落库/记录值。运行时无需 DB。",
"knownDiscrepancies": "swapLongShort.js 的 SwapMarginAmount 用裸 InterestPrincipal(无符号),而 unwindSwapTrade.js 用 InterestDirection 求符号。该差异被冻结在 knownDiscrepancies 中,仅当差异量变化时才报红。"
},
"records": [
{
"id": "UNWIND_STD",
"desc": "标准平仓(unwind):含浮动盈亏 + 利息腿 + 预付金腿",
"eventType": 2,
"deal": { "CloseQty": 1000 },
"floatPosition": { "FloatPnlSum": 50000, "PositionType": 1, "PayDirection": 1, "TradingFee": 20 },
"interestList": [
{ "InterestClosePnL": 1200, "InterestDirection": 1, "InterestPrincipal": 0 }
],
"marginList": [
{ "InterestClosePnL": 300, "InterestDirection": 1, "InterestPrincipal": 50000 }
],
"expected": {
"SwapCloseAmount": 51500,
"SwapRealizedPnL": 51500,
"SwapMarginRebatePnl": 300,
"SwapMarginAmount": -50000
}
},
{
"id": "INCOME_STD",
"desc": "收益结算(income):用 CloseNotionalValue 计价,利息腿+预付金腿",
"eventType": 3,
"deal": { "CloseQty": 0, "CloseNotionalValue": 10200 },
"floatPosition": { "FloatPnlSum": 30000, "PositionType": 1, "PayDirection": 2, "TradingFee": 0 },
"interestList": [
{ "InterestClosePnL": 800, "InterestDirection": 1, "InterestPrincipal": 0 }
],
"marginList": [
{ "InterestClosePnL": 200, "InterestDirection": 2, "InterestPrincipal": 40000 }
],
"expected": {
"SwapCloseAmount": 31000,
"SwapRealizedPnL": 31000,
"SwapMarginRebatePnl": 200,
"SwapMarginAmount": 40000
}
},
{
"id": "LONGSHORT_UNWIND",
"desc": "多空组合平仓(unwindLongShort):从0起,不含浮动盈亏(FloatPnlSum=0)",
"eventType": 4,
"deal": { "CloseQty": 0 },
"floatPosition": { "FloatPnlSum": 0, "PositionType": 1, "PayDirection": 1, "TradingFee": 0 },
"interestList": [],
"marginList": [
{ "InterestClosePnL": 150, "InterestDirection": 1, "InterestPrincipal": 20000 }
],
"expected": {
"SwapCloseAmount": 150,
"SwapRealizedPnL": 150,
"SwapMarginRebatePnl": 150,
"SwapMarginAmount": -20000
}
},
{
"id": "LONGSHORT_SWAP",
"desc": "多空组合互换(swapLongShort)SwapMarginAmount 用裸 InterestPrincipal(无符号) —— 已知差异",
"eventType": 5,
"deal": { "CloseQty": 0 },
"floatPosition": { "FloatPnlSum": 0, "PositionType": 1, "PayDirection": 1, "TradingFee": 0 },
"interestList": [],
"marginList": [
{ "InterestClosePnL": 100, "InterestDirection": 1, "InterestPrincipal": 18000 }
],
"expected": {
"SwapCloseAmount": 100,
"SwapRealizedPnL": 100,
"SwapMarginRebatePnl": 100,
"SwapMarginAmount": 18000
},
"knownDiscrepancies": {
"SwapMarginAmount": 36000
}
}
]
}