fix: 恢复互换平仓交易费用按基础费率计算

This commit is contained in:
tengyufan
2026-08-05 18:26:15 +08:00
parent d5837f2de8
commit 46316c1400
4 changed files with 28 additions and 35 deletions
@@ -111,27 +111,25 @@ namespace YLErp.Modules.SwapModule
}
[TestMethod]
public void PartialCloseTradingFeeAndPendingFeeUseTheSameRoundedOriginalFeeAllocation()
public void ManuallyAdjustedPendingFeeDoesNotOverrideBaseRateCloseFee()
{
var oriPosition = new swap_position
{
PosiFeeType = 0,
PosiTradingFeeUnit = 1.1234m,
PosiTradingFeePending = 113.46m
PosiFeeType = 1,
PosiTradingFeeUnit = 0.123456m,
PosiTradingFeePending = 1235.56m
};
var unwindData = new UnwindData
{
NotionalValue = 10098m,
CloseNotionalValue = 4039.2m,
NotionalQty = 10000m,
CloseQty = 4000m
CloseQty = 10000m
};
var tradingFee = InvokeCalcInitTradingFee(oriPosition, unwindData);
var pendingFee = InvokeCalcInitTradingFeePending(oriPosition, new swap_position(), unwindData);
Assert.AreEqual(45.38m, tradingFee);
Assert.AreEqual(45.38m, pendingFee);
Assert.AreEqual(1234.56m, tradingFee);
Assert.AreEqual(1235.56m, pendingFee);
}
[TestMethod]
+11 -11
View File
@@ -324,19 +324,12 @@ namespace YLErp.Modules.SwapModule
return 0;
}
if (oriPosition.PosiTradingFeeUnit == 0)
if (oriPosition.PosiFeeType == 1)
{
return 0;
return Math.Round(oriPosition.PosiTradingFeeUnit * unwindData.CloseQty, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
}
var closeBase = oriPosition.PosiFeeType == 1 ? unwindData.CloseQty : unwindData.CloseNotionalValue;
var originalBase = oriPosition.PosiFeeType == 1 ? unwindData.NotionalQty : unwindData.NotionalValue;
if (originalBase <= 0)
{
return 0;
}
return Math.Round(oriPosition.PosiTradingFeePending * closeBase / originalBase, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
return Math.Round(oriPosition.PosiTradingFeeUnit / 100m * unwindData.CloseNotionalValue, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
}
private static decimal CalcInitTradingFeePending(swap_position oriPosition, swap_position position, UnwindData unwindData)
@@ -346,7 +339,14 @@ namespace YLErp.Modules.SwapModule
return position?.PosiTradingFeePending ?? 0;
}
return CalcInitTradingFee(oriPosition, unwindData);
var closeBase = oriPosition.PosiFeeType == 1 ? unwindData.CloseQty : unwindData.CloseNotionalValue;
var originalBase = oriPosition.PosiFeeType == 1 ? unwindData.NotionalQty : unwindData.NotionalValue;
if (originalBase <= 0)
{
return position?.PosiTradingFeePending ?? 0;
}
return Math.Round(oriPosition.PosiTradingFeePending * closeBase / originalBase, ConsGlobal.MoneyRound, MidpointRounding.AwayFromZero);
}
/// <summary>
/// 校验上日是否收盘
+9 -6
View File
@@ -43,6 +43,9 @@ function loadUnwindHelpers() {
vueDatePicker() { return {}; },
vueNumberInput() { return {}; }
},
swapPricePrecision: {
createVueInputComponent() { return {}; }
},
tradeHelper: { IsBond() { return false; } },
main: {
post() {
@@ -112,14 +115,14 @@ describe('base-rate pending trading fee', () => {
expectClose(result, 450.00);
});
test('partial close fee and pending fee both use the rounded opening fee allocation', () => {
const tradingFee = swapPosiFeeCalc.calcAllocatedTradingFee(
113.46, consPosiFeeType.Percent, 1.1234, 4039.2, 4000, 10098, 10000);
test('a manually adjusted pending fee does not override the base-rate close fee', () => {
const tradingFee = swapPosiFeeCalc.calcTradingFee(
consPosiFeeType.Unit, 0.123456, 0, 10000);
const pendingFee = swapPosiFeeCalc.calcTradingFeePending(
113.46, consPosiFeeType.Percent, 1.1234, 4039.2, 4000, 10098, 10000, 0.4);
1235.56, consPosiFeeType.Unit, 0.123456, 0, 10000, 0, 10000, 1);
expectClose(tradingFee, 45.38);
expectClose(pendingFee, 45.38);
expectClose(tradingFee, 1234.56);
expectClose(pendingFee, 1235.56);
});
test('without a configured base rate, the legacy close-percent calculation remains', () => {
@@ -213,15 +213,7 @@ const vue = new Vue({
this.deal.ClosePercent);
},
refreshTradingFeeByUnit() {
const allocatedFee = swapPosiFeeCalc.calcAllocatedTradingFee(
this.floatPosition.BeforeCloseFee,
this.floatPosition.PosiFeeType,
this.floatPosition.PosiTradingFeeUnit,
this.deal.CloseNotionalValue,
this.deal.CloseQty,
this.deal.NotionalValue,
this.deal.NotionalQty);
this.floatPosition.TradingFee = allocatedFee !== null ? allocatedFee : swapPosiFeeCalc.calcTradingFee(
this.floatPosition.TradingFee = swapPosiFeeCalc.calcTradingFee(
this.floatPosition.PosiFeeType,
this.floatPosition.PosiTradingFeeUnit,
this.deal.CloseNotionalValue,