feat: 新增成交收益率字段
This commit is contained in:
@@ -15,6 +15,8 @@ using Qdp.Pricing.Base.Implementations;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Text;
|
||||
using YLErp.BLL;
|
||||
using YLErp.BLL.Calculation;
|
||||
using YLErp.BLL.Eod;
|
||||
@@ -303,6 +305,51 @@ namespace YLErp.Modules.SwapModule
|
||||
var swapFlows = DbContext.swap_flow.Where(x => ids.Contains(x.id) && x.DataState == (int)SwapFlowDateStateEnum.等待完成 && x.ClientId > 0).ToList();
|
||||
return swapFlows;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 使用不含费全价(加权平均全精度)+日期 来计算
|
||||
/// </summary>
|
||||
/// <param name="swapFlows"></param>
|
||||
public async Task<decimal?> CalcInitYtm(string symbol, DateTime valueDate, decimal tradingAmountAvg)
|
||||
{
|
||||
|
||||
using var client = new HttpClient();
|
||||
|
||||
var payload = new Dictionary<string, object>
|
||||
{
|
||||
{ "bondKey", symbol },
|
||||
{ "settlementDate", valueDate },
|
||||
{ "fullPrice", tradingAmountAvg }
|
||||
};
|
||||
|
||||
string json = System.Text.Json.JsonSerializer.Serialize(payload);
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
try
|
||||
{
|
||||
HttpResponseMessage response = await client.PostAsync("http://localhost:8080/v1/bond/", content);
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
using var doc = JsonDocument.Parse(responseBody);
|
||||
if (doc.RootElement.TryGetProperty("yield", out var yieldElement))
|
||||
{
|
||||
if (yieldElement.ValueKind == JsonValueKind.Number)
|
||||
{
|
||||
double d = yieldElement.GetDouble();
|
||||
return (decimal)d;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("请求失败: " + ex.Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 簿记前自动校验
|
||||
/// </summary>
|
||||
@@ -347,7 +394,7 @@ namespace YLErp.Modules.SwapModule
|
||||
/// 汇总流水
|
||||
/// </summary>
|
||||
/// <param name="valueDate"></param>
|
||||
public List<swap_flow_merge> SummaryFlow(List<swap_flow> swapFlows, bool save = true)
|
||||
public async Task<List<swap_flow_merge>> SummaryFlow(List<swap_flow> swapFlows, DateTime valueDate, bool save = true)
|
||||
{
|
||||
var swapFlowGroup = swapFlows.GroupBy(g => new { g.ClientId, g.OccurTime, g.UnderlyingCode, g.BsType }).ToList();
|
||||
List<swap_flow_merge> list = new List<swap_flow_merge>();
|
||||
@@ -382,6 +429,8 @@ namespace YLErp.Modules.SwapModule
|
||||
swap_flow_summary.TradingAmountNetAvg = Math.Round(swap_flow_summary.TradingAmountNetAvg ?? 0, 10);
|
||||
swap_flow_summary.TradingAmountNetFeeAvg = swap_flow_summary.TradingQty == 0 ? swap_flow_summary.TradingAmountNetAvg : swap_flow_summary.TradingAmountNetAvg + swap_flow_summary.TradingFeePending * tradeSide / swap_flow_summary.TradingQty;
|
||||
swap_flow_summary.TradingAmountNetFeeAvg = Math.Round(swap_flow_summary.TradingAmountNetFeeAvg ?? 0, 10);
|
||||
// 计算收益率
|
||||
swap_flow_summary.InitYtm = await CalcInitYtm(gourpItem.Key.UnderlyingCode, valueDate, swap_flow_summary.TradingAmountAvg);
|
||||
swap_flow_summary.SetOpt(UserInfo);
|
||||
if (save)
|
||||
{
|
||||
|
||||
@@ -350,6 +350,7 @@ namespace YLErp.Modules.SwapModule
|
||||
td.ValidState = "Valid";
|
||||
td.TradeSource = "系统交易";
|
||||
td.TradeStatus = ConsTrade.确认成交;
|
||||
td.InitYtm = flowMerge.InitYtm ?? 0;
|
||||
return td;
|
||||
}
|
||||
/// <summary>
|
||||
@@ -384,7 +385,8 @@ namespace YLErp.Modules.SwapModule
|
||||
OptTime = DateTime.Now,
|
||||
OptId = UserInfo.UserId,
|
||||
OptName = UserInfo.UserName,
|
||||
UnderlyingInstrumentType = underlying.UnderlyingInstrumentType
|
||||
UnderlyingInstrumentType = underlying.UnderlyingInstrumentType,
|
||||
InitYtm = flowMerge.InitYtm ?? 0
|
||||
};
|
||||
td.swap_positions.Add(floatPosition);
|
||||
swap_position interestPosition = new swap_position()
|
||||
|
||||
Reference in New Issue
Block a user