/** * unwindLegSign.js — 平仓页收付方向符号(纯函数) * ============================================================================ * 把散落在 unwindSwapTrade.js 各计算式里的裸三元(xxx==1 ? ±1 : ∓1)显式化为命名函数。 * 【为什么必须显式化】利息盈亏与保证金返还本金对同一 InterestDirection 枚举符号相反—— * 这是业务事实而非笔误,任何"顺手统一"都会翻转保证金返还方向(资损级 bug): * 利息盈亏(利息腿/保证金腿通用,changeInterestAmount 对两类行都生效): * 收益互换中买方为持有标的向交易商融资,利息=融资成本(买方付出去的钱), * InterestDirection==1(收取) → 盈亏记 +1; * 保证金返还本金:保证金是客户自己交的抵押金,返息/返还本金是把客户自己的钱退回来, * 本金流方向与利息(成本)相反 → 同枚举符号取镜像 -1。 * * 其余两个符号:PayDirection==1(浮动端收取) → +1;PositionType==1(多头) → +1。 * * 加载:浏览器 script 标签(先于 unwindSwapTrade.js);Node:module.exports 供 jest。 */ var UnwindLegSign = (function () { 'use strict'; // Number()===1 与页面原 ==1 对 '1'/true/数字等实际入参等价,且对 null/undefined 同样落到 -1 分支 function interestPnlSign(interestDirection) { return Number(interestDirection) === 1 ? 1 : -1; } function marginRebatePrincipalSign(interestDirection) { return Number(interestDirection) === 1 ? -1 : 1; } function payDirectionSign(payDirection) { return Number(payDirection) === 1 ? 1 : -1; } function positionTypeSign(positionType) { return Number(positionType) === 1 ? 1 : -1; } return Object.freeze({ interestPnlSign: interestPnlSign, marginRebatePrincipalSign: marginRebatePrincipalSign, payDirectionSign: payDirectionSign, positionTypeSign: positionTypeSign }); }()); if (typeof module === 'object' && module.exports) module.exports = UnwindLegSign;