fix: 兼容TRS日终推送历史利息腿类别为空

This commit is contained in:
tengyufan
2026-08-27 13:16:01 +08:00
parent 679117f82a
commit 877cf9dc4f
2 changed files with 99 additions and 8 deletions
@@ -142,6 +142,88 @@ namespace YLErp.Modules.EodModuleTests
Assert.AreEqual(0m, item.InitMarginLoss);
}
[TestMethod]
public void BuildContract_历史类别为空_仍推送全部TRS合约()
{
var valueDate = new DateTime(2026, 2, 10);
var eodSwap = new eod_swap { ValueDate = valueDate, SwapTradeId = 1645, SwapTradeNo = "ZSZQ-IS-202602090001" };
var positions = new List<eod_swap_position>
{
new() { SwapTradeId = 1645, PositionId = 33306, UnderlyingCode = "220208.IB", PositionType = 1 },
new() { SwapTradeId = 1645, PositionId = 33307, InterestMode = (int)InterestModeEnum., InterestRateDefault = 0.001m, InterestDirection = 1 }
};
var swapPositions = new Dictionary<long, swap_position>
{
[33306] = new() { id = 33306, category_tag = null },
[33307] = new() { id = 33307, category_tag = null }
};
var item = TrsContractKafkaPushService.BuildContract(
eodSwap,
new Dictionary<int, trade> { [1645] = new() { id = 1645, UnderlyingCode = "220208.IB" } },
positions,
swapPositions);
Assert.AreEqual(0m, item.FixedRate);
Assert.AreEqual(1, item.InterestDirection);
Assert.AreEqual(1, item.FloatingDirection);
}
[TestMethod]
public void BuildContract_增强收益腿不参与固定利率取值()
{
var eodSwap = new eod_swap { ValueDate = new DateTime(2026, 8, 24), SwapTradeId = 7 };
var positions = new List<eod_swap_position>
{
new() { SwapTradeId = 7, PositionId = 101, UnderlyingCode = "600000.SH", PositionType = 2 },
new() { SwapTradeId = 7, PositionId = 102, InterestMode = (int)InterestModeEnum., InterestRateDefault = 0.0123m, InterestDirection = 1 },
new() { SwapTradeId = 7, PositionId = 103, InterestMode = (int)InterestModeEnum., InterestRateDefault = 0.0999m, InterestDirection = 2 }
};
var swapPositions = new Dictionary<long, swap_position>
{
[101] = new() { id = 101, category_tag = null },
[102] = new() { id = 102, category_tag = "互换利率" },
[103] = new() { id = 103, category_tag = "增强收益" }
};
var item = TrsContractKafkaPushService.BuildContract(
eodSwap,
new Dictionary<int, trade> { [7] = new() { id = 7, UnderlyingCode = "600000.SH" } },
positions,
swapPositions);
Assert.AreEqual(0.0123m, item.FixedRate);
Assert.AreEqual(1, item.InterestDirection);
Assert.AreEqual(2, item.FloatingDirection);
}
[TestMethod]
public void BuildContract_多条互换利率腿_取第一条()
{
var eodSwap = new eod_swap { ValueDate = new DateTime(2026, 8, 24), SwapTradeId = 7 };
var positions = new List<eod_swap_position>
{
new() { SwapTradeId = 7, PositionId = 101, UnderlyingCode = "600000.SH", PositionType = 1 },
new() { SwapTradeId = 7, PositionId = 102, InterestMode = (int)InterestModeEnum., InterestRateDefault = 0.0123m, InterestDirection = 1 },
new() { SwapTradeId = 7, PositionId = 103, InterestMode = (int)InterestModeEnum., InterestRateDefault = 0.0456m, InterestDirection = 2 }
};
var swapPositions = new Dictionary<long, swap_position>
{
[101] = new() { id = 101, category_tag = null },
[102] = new() { id = 102, category_tag = "互换利率" },
[103] = new() { id = 103, category_tag = "互换利率" }
};
var item = TrsContractKafkaPushService.BuildContract(
eodSwap,
new Dictionary<int, trade> { [7] = new() { id = 7, UnderlyingCode = "600000.SH" } },
positions,
swapPositions);
Assert.AreEqual(0.0123m, item.FixedRate);
Assert.AreEqual(1, item.InterestDirection);
}
private static TestableTrsContractKafkaPushService CreateService(RecordingKafkaProducer producer, DateTime valueDate)
{
return new TestableTrsContractKafkaPushService(