Files
2024-05-09 14:06:26 +08:00

109 lines
3.7 KiB
C#

using YLErp.DBModels.Converts;
using YLErp.Modules.TradeModule.DealModule;
namespace YLErp.Modules.ApiModule
{
[TestClass]
public class TradeDealTest : UnitTestBase
{
[TestMethod("api/v1/trade/group_options_close")]
public void TestCreateClientMethod()
{
var UnwindType = "部分平仓";
var TradeNumber = "CW202154518046X0002";
var ValueDate = new DateTime(2022, 1, 13);
var UnderlyingPrice = 17.04;
var UnwindAmountFlag = "百分比";
var UnwindAmount = 0.33;
var td = DbContextFactory.GetYLDbContext().trade.Where(n => n.TradeNumber == TradeNumber).FirstOrDefault();
if (td == null)
{
throw new ServiceException("交易信息不存在");
}
if (td.TradeType != "结构化交易" || td.IsGroup != 1)
{
throw new ServiceException("所选交易非组合交易主交易,不支持此API调用");
}
var tc = new trade_cash
{
id = 0,
TradeId = td.id,
ValueDate = ValueDate,
ExceciseType = null,
TradeType = BuySellConvert.GetClientBuySell(td.BuySell),
CallPut = null,
Strike = null,
Notional = td.Notional,
Amount = 0,
Action = UnwindType,
ValidState = null,
Status = null,
FinalPrice = UnderlyingPrice,
UnwindPrice = null,
UnwindVol = null,
VolType = null,
UnwindType = null,
UnwindNotional = null,
ExtraAmount = null,
SettleDate = null,
Comments = null,
ExerciseWay = null,
TradeAmount = null,
UnwindTradeAmount = td.TradeAmount,
UnwindPercentRate = null,
UnwindPricePercentRate = null,
BarrierPrice = null,
HappenedDate = null,
ConfirmDate = System.DateTime.MinValue,
ParentTradeId = 0,
ParentTradeCashId = 0,
SpotPrice = null,
NotionalPercentRate = null,
TradePremium = 0,
IsDeleted = false,
AdvanceMoney = 0,
IsLastAction = false
};
if (td.IsUsePremiumRate == true)
{
if (UnwindAmountFlag == "百分比")
{
tc.UnwindPercentRate = UnwindAmount;
}
else if (UnwindAmountFlag == "名义本金")
{
tc.UnwindStockEqvNotional = UnwindAmount;
}
else
{
throw new ServiceException("交易是以'名义本金方式'成交的,仅支持以'百分比'和'名义本金'方式平仓");
}
}
else
{
if (UnwindAmountFlag == "数量")
{
tc.UnwindTradeAmount = UnwindAmount;
}
else
{
throw new ServiceException("交易是以'数量方式'成交的,仅支持'数量'方式平仓");
}
}
new TradeUnwindService(OptUserInfo.SystemUser).SaveGroupTradeCash(new YLErp.Model.SaveGroupTradeCashReq
{
trade_cash = tc,
tradeIds = new System.Collections.Generic.List<int> { td.id },
});
Console.WriteLine("完成");
}
}
}