/// <summary> /// 类型1改单——生成新委托,下单,并回推改单结果到前台 /// </summary> /// <param name="request"></param> internal void ProcessType1_NewOrder(HKModifyOrderRequest request) { LogHelper.WriteDebug("M——————>ModifyOrderProcessor.ProcessType1_NewOrder生成新委托,下单,并回推改单结果到前台" + request); HKOrderRequest newRequest = CreateNewType1Request(request); HKModifyOrderPushBack pushBack = new HKModifyOrderPushBack(); pushBack.OriginalRequestNumber = request.EntrustNubmer; pushBack.TradeID = request.TraderId; pushBack.CallbackChannlId = request.ChannelID; var res = OrderAccepterService.Service.DoHKOrder(newRequest); pushBack.IsSuccess = res.IsSuccess; pushBack.Message = res.OrderMessage; if (res.IsSuccess) { HKDataAccess.UpdateEntrustModifyOrderNumber(res.OrderId, request.EntrustNubmer); //记录成功改单委托记录明细,方便查询和关联查询 HKDataAccess.AddModifyOrderSuccessDatils(res.OrderId, request.EntrustNubmer, 1); pushBack.NewRequestNumber = res.OrderId; } else { request.Message = res.OrderMessage; HKDataAccess.UpdateModifyOrderRequest(request); } //将改单结果推给前台 CounterOrderService.Instance.AcceptHKModifyOrder(pushBack); }
public override bool Validate(HKOrderRequest request, ref string strMessage) { //根据要求,柜台不再做涨跌幅判断,由撮合处理 return(true); #region 根据要求,柜台不再做涨跌幅判断,由撮合处理 以下注释 //string errMsg = "港股涨跌幅检验失败!"; //string errCode = "GT-1253"; //decimal orderPrice = (decimal)request.OrderPrice; //decimal orderPriceD = (decimal)request.OrderPrice; //HighLowRangeValue value = MCService.HLRangeProcessor.GetHKStockHighLowRangeValueByCommodityCode(request.Code, orderPriceD, request.OrderWay, request.BuySell); //if (value == null) //{ // return true; //} //if (value.RangeType != Types.HighLowRangeType.HongKongPrice) //{ // decimal high = value.HighRangeValue; // decimal low = value.LowRangeValue; // if (orderPrice >= low && orderPrice <= high) // { // return true; // } // strMessage = errCode + ":" + errMsg; // return false; //} #endregion }
public OrderResponse DoHKOrder(HKOrderRequest order) { if (!IsServiceOk) { return new OrderResponse { OrderMessage = ServiceErrorMsg } } ; order.ChannelID = Channelid; OrderResponse response = null; try { response = doOrderClient.DoHKOrder(order); } catch (Exception ex) { LogHelper.WriteError(ex.Message, ex); response = new OrderResponse(); response.IsSuccess = false; response.OrderMessage = ServiceErrorMsg; IsServiceOk = false; } return(response); }
/// <summary> /// 构建港股委托单 /// </summary> /// <param name="order"></param> /// <param name="originalOrder"></param> /// <param name="strHoldingAccount"></param> /// <param name="strCapitalAccount"></param> /// <param name="iCurType"></param> /// <param name="strMessage"></param> /// <returns></returns> public static string BuildHKOrder(ref HK_TodayEntrustInfo order, HKOrderRequest originalOrder, string strHoldingAccount, string strCapitalAccount, int iCurType, ref string strMessage) { return(BuildHKOrder(ref order, originalOrder, strHoldingAccount, strCapitalAccount, iCurType, false, "", ref strMessage)); }
/// <summary> /// 获取港股交易费用 /// </summary> /// <param name="request">港股委托</param> /// <returns>港股交易费用结果</returns> public static HKCostResult ComputeHKCost(HKOrderRequest request) { int? bc = MCService.CommonPara.GetBreedClassIdByCommodityCode(request.Code, Types.BreedClassTypeEnum.HKStock); HKCostResult result = null; if (!bc.HasValue) { return(null); } int breedClassID = bc.Value; HK_SpotCosts cost = MCService.HKTradeRulesProxy.GetSpotCostsByBreedClassID(breedClassID); if (cost == null) { return(null); } try { result = InternalComputeHKCost(request, cost); } catch (Exception ex) { string errCode = "GT-1701"; string errMsg = "无法获取港股交易费用。"; VTException exception = new VTException(errCode, errMsg, ex); LogHelper.WriteError(exception.ToString(), exception); throw exception; } return(result); }
public override bool Validate(HKOrderRequest request, ref string strMessage) { bool result = false; string errMsg = "超过当前港股单笔最大委托量!"; string errCode = "GT-1251"; strMessage = errCode + ":" + errMsg; //int maxUnit = TradeRules.MaxLeaveQuantityUnit; int maxUnit = TradeRules.PriceUnit;//这与MaxLeaveQuantityUnit字段同相同的 Types.UnitType maxUnitType; try { maxUnitType = (Types.UnitType)maxUnit; } catch { return(false); } decimal scale = MCService.GetTradeUnitScale(Types.BreedClassTypeEnum.HKStock, request.Code, request.OrderUnitType); decimal scale2 = MCService.GetTradeUnitScale(Types.BreedClassTypeEnum.HKStock, request.Code, maxUnitType); var orderAmount = (decimal)request.OrderAmount * scale; //===Update By;李健华 2009-11-10 === // 因为港股规则里填写的最大委托量为手而之前的现货直接填写的为股,所以这里在要转换过来为股 //,而在这里验证的时候传入的都为股单位 //int? maxSingle = TradeRules.MaxLeaveQuantity; int?maxSingle = TradeRules.MaxLeaveQuantity; if (maxSingle.HasValue) { int perHand = MCService.HKTradeRulesProxy.GetHKPerHandThighOrShareByCode(request.Code, out strMessage); maxSingle = maxSingle.Value * perHand; //==================== decimal maxAmount = maxSingle.Value * scale2; if (orderAmount <= maxAmount) { result = true; strMessage = ""; } else { if (string.IsNullOrEmpty(strMessage)) { strMessage = errCode + ":" + errMsg; } } } return(result); }
/// <summary> /// 获取港股交易费用 /// </summary> /// <param name="code">商品代码</param> /// <param name="price">委托价格</param> /// <param name="amount">委托数量</param> /// <param name="unitType">委托单位类型</param> /// <param name="buySell">买卖方向</param> /// <returns>港股交易费用结果</returns> public static HKCostResult ComputeHKCost(string code, float price, int amount, Types.UnitType unitType, Types.TransactionDirection buySell) { HKOrderRequest request = new HKOrderRequest(); request.Code = code; request.OrderPrice = price; request.OrderAmount = amount; request.OrderUnitType = unitType; request.BuySell = buySell; return(ComputeHKCost(request)); }
/// <summary> /// 卖持仓检查 /// </summary> /// <param name="strMessage"></param> /// <param name="hkEntrustInfo"></param> /// <param name="request"></param> /// <returns></returns> private bool PO_HoldValidate_Sell(ref string strMessage, HK_TodayEntrustInfo hkEntrustInfo, HKOrderRequest request) { bool result = false; strMessage = "GT-2420:[港股改单委托检验]卖持仓检查,无持仓--港股改单委托失败"; //var ahtMemory = MemoryDataManager.HKHoldMemoryList.GetByHoldAccountAndCurrencyType(HoldingAccount, Code, // CurrencyType); //if (ahtMemory == null) //{ var ahtMemory = HKCommonLogic.GetHoldMemoryTable(hkEntrustInfo.HoldAccount, hkEntrustInfo.Code, hkEntrustInfo.CurrencyTypeID); //} if (ahtMemory == null || ahtMemory.Data == null) { return(false); } var aht = ahtMemory.Data; int position = Convert.ToInt32(aht.AvailableAmount); //真正的可用量是要减去真正的改单量增加或者减少量 //而真正的改单量增加量为=现在改单委托量-原委托量; int nowAddAmount = Convert.ToInt32(request.OrderAmount) - hkEntrustInfo.EntrustAmount; //不能直接把冻结量加上,因为冻结量可能不为本单的冻结量,可能还有别的单下的冻结量 position = position + hkEntrustInfo.EntrustAmount - hkEntrustInfo.TradeAmount; //则当前的真正的可用持仓量为 position = position - nowAddAmount; //持仓帐户是否存在判断 //result = ValidateCenter.ValidateHKMinVolumeOfBusiness(request, position, ref strMessage); HKStockMinVolumeOfBusinessCommand command = new HKStockMinVolumeOfBusinessCommand(BreedClassID, position); result = command.Validate(request, ref strMessage); if (!result) { strMessage += "--港股改单委托失败"; } if (result) { strMessage = ""; } return(result); }
public void ProcessDoOrder(OrderResponse response, HKOrderRequest request) { HKMessage message = new HKMessage(); message.BuySell = request.BuySell == GTA.VTS.Common.CommonObject.Types.TransactionDirection.Buying ? "买" : "卖"; message.CapitalAccount = request.FundAccountId; message.Code = request.Code; message.EntrustAmount = request.OrderAmount.ToString(); message.EntrustNumber = response.OrderId; message.EntrustPrice = request.OrderPrice.ToString(); //message.EntrustType = request.OrderWay == TypesOrderPriceType.OPTLimited ? "限价" : "市价"; switch (request.OrderWay) { case Types.HKPriceType.LO: message.EntrustType = "限价单"; break; case Types.HKPriceType.ELO: message.EntrustType = "增强限价单"; break; case Types.HKPriceType.SLO: message.EntrustType = "特别限价单"; break; } message.OrderMessage = response.OrderMessage; message.OrderStatus = "未报02"; message.TradeAmount = "0"; message.TradeTime = ""; listLock.EnterWriteLock(); try { hkMessageList.Add(message); } finally { listLock.ExitWriteLock(); } if (!response.IsSuccess) { message.EntrustNumber = System.Guid.NewGuid().ToString(); message.OrderStatus = "废单06"; } hkMessageCache.Add(message.EntrustNumber, message); HasChanged = true; }
public override bool Validate(HKOrderRequest request, ref string strMessage) { string errMsg = "交易员没有此品种的交易权限!"; string errCode = "GT-1254"; string tradeID = request.TraderId; if (string.IsNullOrEmpty(tradeID)) { strMessage = errCode + ":" + errMsg; return(false); } int userid = 0; try { userid = int.Parse(tradeID.Trim()); } catch (Exception ex) { LogHelper.WriteError(ex.Message, ex); strMessage = errCode + ":" + errMsg; return(false); } var rightList = MCService.CommonPara.GetTransactionRightTable(userid); if (Utils.IsNullOrEmpty(rightList)) { strMessage = errCode + ":" + errMsg; return(false); } foreach (UM_DealerTradeBreedClass tradeBreedClass in rightList) { if (!tradeBreedClass.BreedClassID.HasValue) { continue; } if (this.BreedClassID == tradeBreedClass.BreedClassID.Value) { return(true); } } strMessage = errCode + ":" + errMsg; return(false); }
public override bool Validate(HKOrderRequest request, ref string strMessage) { string errMsg = "港股委托数量必须大于零!"; string errCode = "GT-1255"; strMessage = errCode + ":" + errMsg; if (request.OrderAmount <= 0) { return(false); } strMessage = ""; return(true); }
/// <summary> /// 获取交易品种并检验 /// </summary> /// <param name="request">股票委托请求</param> /// <param name="strMessage">现货检验错误信息</param> /// <param name="iBreed">品种标识</param> public bool Validate(HKOrderRequest request, ref string strMessage, int iBreed) { bool bresult = false; HKStockRuleContainer src = GetContainer(iBreed); if (src == null) { src = new HKStockRuleContainer(iBreed); SetContainer(iBreed, src); } bresult = src.ValidateAllRules(request, ref strMessage); //调用港股检验总方法 return(bresult); }
/// <summary> /// 港股委托规则检验 /// </summary> /// <param name="request">股票委托对象</param> /// <param name="errMsg">返回错误检验信息</param> /// <returns>是否成功</returns> public bool ValidateHKStockTradeRule(HKOrderRequest request, ref string errMsg) { CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(request.Code, Types.BreedClassTypeEnum.HKStock); bool result = false; if (breedClass != null) { if (!breedClass.BreedClassTypeID.HasValue || breedClass.BreedClassTypeID.Value != (int)Types.BreedClassTypeEnum.HKStock) { errMsg = "当前代码不为港股类别--" + breedClass.BreedClassTypeID.Value; return(false); } result = HKStockTradingRuleValidater.Validate(request, ref errMsg, Convert.ToInt32(breedClass.BreedClassID)); } return(result); }
private HKOrderRequest CreateNewType3Request(HKModifyOrderRequest request, HK_TodayEntrustInfo tet, float amount) { HKOrderRequest newRequest = new HKOrderRequest(); newRequest.BuySell = (Types.TransactionDirection)tet.BuySellTypeID; newRequest.ChannelID = tet.CallbackChannlID; newRequest.Code = request.Code; newRequest.FundAccountId = request.FundAccountId; newRequest.OrderAmount = amount; newRequest.OrderPrice = request.OrderPrice; newRequest.OrderUnitType = (Types.UnitType)tet.TradeUnitID; newRequest.OrderWay = Types.HKPriceType.LO; newRequest.PortfoliosId = tet.PortfolioLogo; newRequest.TraderId = request.TraderId; newRequest.TraderPassword = request.TraderPassword; return(newRequest); }
/// <summary> /// 根据港股改单委托创建新的委托 /// </summary> /// <param name="request"></param> /// <returns></returns> private HKOrderRequest CreateNewType1Request(HKModifyOrderRequest request) { var tet = HKDataAccess.GetTodayEntrustTable(request.EntrustNubmer); HKOrderRequest newRequest = new HKOrderRequest(); newRequest.BuySell = (Types.TransactionDirection)tet.BuySellTypeID; newRequest.ChannelID = tet.CallbackChannlID; newRequest.Code = request.Code; newRequest.FundAccountId = request.FundAccountId; newRequest.OrderAmount = request.OrderAmount; newRequest.OrderPrice = request.OrderPrice; newRequest.OrderUnitType = (Types.UnitType)tet.TradeUnitID; newRequest.OrderWay = Types.HKPriceType.LO; newRequest.PortfoliosId = tet.PortfolioLogo; newRequest.TraderId = request.TraderId; newRequest.TraderPassword = request.TraderPassword; return(newRequest); }
/// <summary> /// 港股最小交易单位校验 /// 供调用者直接调用 /// </summary> /// <param name="request">委托</param> /// <param name="position">当前委托对应的商品的持仓量</param> /// <param name="errMsg">错误信息</param> /// <returns>是否校验成功</returns> public static bool ValidateHKMinVolumeOfBusiness(HKOrderRequest request, int position, ref string errMsg) { CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(request.Code, Types.BreedClassTypeEnum.HKStock); bool result = false; if (breedClass != null) { int breedClassTypeID = breedClass.BreedClassTypeID.Value; int breedClassID = breedClass.BreedClassID; if (breedClassTypeID != (int)Types.BreedClassTypeEnum.HKStock) { return(false); } HKStockMinVolumeOfBusinessCommand command = new HKStockMinVolumeOfBusinessCommand(breedClassID, position); result = command.Validate(request, ref errMsg); } return(result); }
/// <summary> /// 港股校验 /// </summary> /// <param name="request">港股委托</param> /// <param name="errMsg">错误信息</param> /// <returns>校验成功失败结果</returns> public static bool Validate(HKOrderRequest request, ref string errMsg) { try { //内部校验 LocalHKStockValidater local = new LocalHKStockValidater(request); bool result = local.Check(out errMsg); //外部校验 if (result) { result = McValidater.GetInstance().ValidateHKStockTradeRule(request, ref errMsg); } return(result); //return true; } catch (Exception ex) { LogHelper.WriteError(ex.ToString(), ex); return(false); } }
/// <summary> /// 根据港股委托单和港股交易费用规则统计交易费用实体 /// </summary> /// <param name="request">委托单</param> /// <param name="cost">交易费用规则</param> /// <returns>返回港股交易费统计实体</returns> private static HKCostResult InternalComputeHKCost(HKOrderRequest request, HK_SpotCosts cost) { CM_BreedClass breedClass = MCService.CommonPara.GetBreedClassByCommodityCode(request.Code, Types.BreedClassTypeEnum.HKStock); HKCostResult result = new HKCostResult(); result.Code = request.Code; decimal orderPrice = (decimal)request.OrderPrice; decimal scale = MCService.GetTradeUnitScale(Types.BreedClassTypeEnum.HKStock, request.Code, request.OrderUnitType); //以计价单位计算的委托量 var orderAmount = (decimal)request.OrderAmount * scale; //成交额 var dealAmount = orderPrice * orderAmount; #region 1.印花税 /// 1.印花税 decimal stamp = cost.StampDuty.Value / 100; decimal stampStart = cost.StampDutyStartingpoint.Value; if (cost.StampDutyTypeID.HasValue) { int stampType = cost.StampDutyTypeID.Value; decimal stampVal = stamp * dealAmount; if (stampVal < stampStart) { stampVal = stampStart; } stampVal = Utils.Round(stampVal); switch ((Types.GetValueTypeEnum)stampType) { case Types.GetValueTypeEnum.Single: break; case Types.GetValueTypeEnum.Scope: break; case Types.GetValueTypeEnum.Turnover: break; case Types.GetValueTypeEnum.Thigh: break; case Types.GetValueTypeEnum.SingleBuy: if (request.BuySell == Types.TransactionDirection.Buying) { result.StampDuty = stampVal; } break; case Types.GetValueTypeEnum.SingleSell: if (request.BuySell == Types.TransactionDirection.Selling) { result.StampDuty = stampVal; } break; case Types.GetValueTypeEnum.TwoEdge: result.StampDuty = stampVal; break; case Types.GetValueTypeEnum.No: break; default: break; } } #endregion #region 2.佣金 /// 2.佣金 if (cost.Commision.HasValue) { decimal comm = cost.Commision.Value / 100; decimal commVal = comm * dealAmount; decimal commStart = 0; if (cost.CommisionStartingpoint.HasValue) { commStart = cost.CommisionStartingpoint.Value; } if (commVal < commStart) { commVal = commStart; } commVal = Utils.Round(commVal); result.Commision = commVal; } #endregion #region 过户费 /// 3.过户费 if (cost.TransferToll.HasValue) { decimal transVal = cost.TransferToll.Value / 100; transVal = Utils.Round(transVal); result.TransferToll = transVal; } #endregion #region 4.交易手续费 #region old code ///// 4.交易手续费 ////public decimal PoundageSingleValue { get; set; } //if (cost.GetValueTypeID.HasValue) //{ // int poundType = cost.GetValueTypeID.Value; // //交易手续费单值 single double // switch (poundType) // { // case (int)Types.GetValueTypeEnum.Single: // decimal pound = cost.PoundageValue.Value / 100; // decimal poundValue = pound * dealAmount; // poundValue = Utils.Round(poundValue); // result.PoundageSingleValue = poundValue; // break; // case (int)Types.GetValueTypeEnum.Scope: // IList<XH_SpotRangeCost> costs = // MCService.SpotTradeRules.GetSpotRangeCostByBreedClassID(breedClass.BreedClassID); // foreach (XH_SpotRangeCost spotRangeCost in costs) // { // int fieldRangeID = spotRangeCost.FieldRangeID; // decimal pound2 = spotRangeCost.Value.Value; // pound2 = Utils.Round(pound2); // CM_FieldRange fieldRange = MCService.GetFieldRange(fieldRangeID); // //是否在当前字段范围内 // bool isExist = MCService.CheckFieldRange(dealAmount, fieldRange); // if (isExist) // { // result.PoundageSingleValue = pound2; // break; // } // } // break; // } //} #endregion decimal pound = cost.PoundageValue.Value / 100; decimal poundValue = dealAmount * pound; poundValue = Utils.Round(poundValue); result.PoundageSingleValue = poundValue; #endregion #region 5.监管费 /// 5.监管费 //public decimal MonitoringFee { get; set; } if (cost.MonitoringFee.HasValue) { decimal monitor = cost.MonitoringFee.Value / 100; decimal monitorVal = monitor * dealAmount; monitorVal = Utils.Round(monitorVal); result.MonitoringFee = monitorVal; } #endregion #region 6.结算费(无) /// 6.结算费 result.ClearingFees = 0; #endregion #region 7.交易系统使用费 /// 7.交易系统使用费 if (cost.SystemToll.HasValue) { result.TradeSystemFees = cost.SystemToll.Value; } #endregion string format = "港股费用计算[代码={0},价格={1},数量={2},单位={3},方向={4}]"; string desc = string.Format(format, request.Code, request.OrderPrice, request.OrderAmount, request.OrderUnitType, request.BuySell); LogHelper.WriteDebug(desc + result); return(result); }
/// <summary> /// 构建港股委托单 /// </summary> /// <param name="order"></param> /// <param name="originalOrder"></param> /// <param name="strHoldingAccount"></param> /// <param name="strCapitalAccount"></param> /// <param name="iCurType"></param> /// <param name="modifyOrderNumber">原始委托单号</param> /// <param name="strMessage"></param> /// <param name="isModifyOrder">是否是改单</param> /// <returns></returns> public static string BuildHKOrder(ref HK_TodayEntrustInfo order, HKOrderRequest originalOrder, string strHoldingAccount, string strCapitalAccount, int iCurType, bool isModifyOrder, string modifyOrderNumber, ref string strMessage) { if (order == null) { order = new HK_TodayEntrustInfo(); } order.EntrustNumber = BuildHKOrderNo(); order.CurrencyTypeID = iCurType; order.TradeUnitID = (int)originalOrder.OrderUnitType; order.EntrustAmount = (int)originalOrder.OrderAmount; order.EntrustPrice = Convert.ToDecimal(originalOrder.OrderPrice); order.EntrustTime = DateTime.Now; order.OfferTime = DateTime.Now; order.OrderPriceType = (int)originalOrder.OrderWay; order.BuySellTypeID = (int)originalOrder.BuySell; order.OrderStatusID = (int)Types.OrderStateType.DOSUnRequired; if (strHoldingAccount == null) { strHoldingAccount = ""; } order.HoldAccount = strHoldingAccount.Trim(); if (strCapitalAccount == null) { strCapitalAccount = ""; } order.CapitalAccount = strCapitalAccount.Trim(); if (originalOrder.PortfoliosId == null) { originalOrder.PortfoliosId = ""; } order.PortfolioLogo = originalOrder.PortfoliosId.Trim(); if (originalOrder.Code == null) { originalOrder.Code = ""; } order.Code = originalOrder.Code.Trim(); order.TradeAmount = 0; order.TradeAveragePrice = 0; order.CancelAmount = 0; order.CancelLogo = true; if (originalOrder.ChannelID == null) { originalOrder.ChannelID = ""; } order.CallbackChannlID = originalOrder.ChannelID.Trim(); order.IsModifyOrder = isModifyOrder; order.ModifyOrderNumber = modifyOrderNumber; order.OrderMessage = ""; order.McOrderID = ""; CheckEntrustLength(order); #if (DEBUG) LogHelper.WriteDebug("HKCommonLogic.BuildHKOrder:" + order); #endif HK_TodayEntrustDal dal = new HK_TodayEntrustDal(); dal.Add(order); return(order.EntrustNumber); }
public override bool Validate(HKOrderRequest request, ref string strMessage) { bool result = false; string errMsg = "港股最小变动价位检验失败!"; string errCode = "GT-1252"; strMessage = errCode + ":" + errMsg; #region ////// // 价位(靠后不靠前)(港元) 最小变动单位 //0.01-0.25 0.001 //0.25-0.50 0.005 //0.50-10.00 0.010 //10.00-20.00 0.020 //20.00-100.00 0.050 //100-200.00 0.100 //200.00-500.00 0.200 //500.00-1,000.00 0.500 //1,000.00-2,000.00 1.000 //2,000.00-5,000.00 2.000 //5,000.00-9,995.00 5.000 ////从高到低判断 //if (5000.00F < orderPrice && orderPrice >= 9995.00F) //{ // // 5.000 //} //if (2000.00F < orderPrice && orderPrice >= 5000.00F) //{ // // 2.000 //} //if (1000.00F < orderPrice && orderPrice >= 2000.00F) //{ // // 1.000 //} //if (500.00F < orderPrice && orderPrice >= 1000.00F) //{ // // 0.500 //} //if (200.00F < orderPrice && orderPrice >= 500.00F) //{ // // 0.200 //} //if (100.00F < orderPrice && orderPrice >= 200.00F) //{ // // 0.100 //} //if (20.00F < orderPrice && orderPrice >= 100.00F) //{ // // 0.050 //} //if (10.00F < orderPrice && orderPrice >= 20.00F) //{ // // 0.020 //} //if (0.50F < orderPrice && orderPrice >= 10.00F) //{ // // 0.010 //} //if (0.25F < orderPrice && orderPrice >= 0.50F) //{ // //0.005 //} //if (0.01F < orderPrice && orderPrice >= 0.25F) //{ // //是否满足最小变动价位 // if (orderPrice % 0.001 == 0) // { // strMessage = ""; // return true; // } //} #endregion decimal orderPrice = (decimal)request.OrderPrice; foreach (HK_MinPriceFieldRange item in MinChangePriceValue) { //价位(靠后不靠前)(港元) if (item.LowerLimit.Value < orderPrice && orderPrice <= item.UpperLimit.Value) { if (orderPrice % item.Value == 0) { strMessage = ""; return(true); } } } #region old code //int? min = TradeRules.ValueTypeMinChangePrice; //if (!min.HasValue) //{ // return false; //} //int minValueType = min.Value; //decimal orderPrice = (decimal)request.OrderPrice; //switch (minValueType) //{ // case (int)Types.GetValueTypeEnum.Single: // decimal? minSingle = TradeRules.MinChangePrice; // if (minSingle.HasValue) // { // decimal minSingleValue = minSingle.Value; // //是否满足最小变动价位 // if (orderPrice % minSingleValue == 0) // { // result = true; // strMessage = ""; // } // } // break; // case (int)Types.GetValueTypeEnum.Scope: // foreach (XH_MinChangePriceValue changePriceValue in MinChangePriceValue) // { // if (changePriceValue.Value.HasValue) // { // decimal fValue = changePriceValue.Value.Value; // CM_FieldRange fieldRange = MCService.GetFieldRange(changePriceValue.FieldRangeID); // //是否在当前字段范围内 // result = MCService.CheckFieldRange(orderPrice, fieldRange); // if (result) // { // //是否满足最小变动价位 // if (orderPrice % fValue == 0) // { // strMessage = ""; // return true; // } // } // } // } // break; //} #endregion return(result); }
/// <summary> /// 根据改单请求和改单类型,改单委托的买卖方向,检验相关验证方法 /// </summary> /// <param name="hkModifyOrder"></param> /// <param name="modifyType"></param> /// <param name="entrusInfo"></param> /// <param name="strMessage"></param> /// <returns></returns> public bool Validate(HKModifyOrderRequest hkModifyOrder, HK_TodayEntrustInfo entrusInfo, int breedClassID, ref string strMessage) { BreedClassID = breedClassID; bool reust = false; int modifyType = 0; //改单类型 #region 判断改单类型 //未注报 if (entrusInfo.OrderStatusID == (int)Types.OrderStateType.DOSUnRequired) { modifyType = 1; } //已报、部成 if (entrusInfo.OrderStatusID == (int)Types.OrderStateType.DOSIsRequired || entrusInfo.OrderStatusID == (int)Types.OrderStateType.DOSPartDealed) { if ((decimal)hkModifyOrder.OrderPrice == entrusInfo.EntrustPrice && hkModifyOrder.OrderAmount < entrusInfo.EntrustAmount) { modifyType = 2; } else { modifyType = 3; } } #endregion if (modifyType == 0) { strMessage = "GT-2250:[港股改单委托验证]当前委托无法改单"; return(false); } #region 为适用之前的方法组装下单请求实体 HKOrderRequest request = new HKOrderRequest(); request.Code = hkModifyOrder.Code; request.ChannelID = hkModifyOrder.ChannelID; request.BuySell = (CommonObject.Types.TransactionDirection)entrusInfo.BuySellTypeID; request.OrderAmount = hkModifyOrder.OrderAmount; request.OrderPrice = hkModifyOrder.OrderPrice; request.FundAccountId = entrusInfo.CapitalAccount; request.OrderUnitType = (GTA.VTS.Common.CommonObject.Types.UnitType)entrusInfo.TradeUnitID; request.OrderWay = (GTA.VTS.Common.CommonObject.Types.HKPriceType)entrusInfo.OrderPriceType; #endregion #region 1.零股检验 //零股检验 HKStockZeroVolumeOfBusinessCommand zerovolume = new HKStockZeroVolumeOfBusinessCommand(BreedClassID); reust = zerovolume.Validate(request, ref strMessage); if (!reust) { return(false); } #endregion #region 2.单笔最大委托量检验命令 //单笔最大委托量检验命令 HKStockMaxLeaveQuantityRangeValueCommand maxLeave = new HKStockMaxLeaveQuantityRangeValueCommand(BreedClassID); reust = maxLeave.Validate(request, ref strMessage); if (!reust) { return(false); } #endregion #region 3.不是第二种类型量减的并且价格有改动的验证最小变动价格 //不是第二种类型量减的并且价格有改动的验证最小变动价格 if (modifyType != 2 && (decimal)hkModifyOrder.OrderPrice != entrusInfo.EntrustPrice) { HKStockMinChangePriceValueCommand minChange = new HKStockMinChangePriceValueCommand(BreedClassID); reust = minChange.Validate(request, ref strMessage); if (!reust) { return(false); } } #endregion #region 委托量有所改变则验证相关持仓(宋涛1116:此处不需要进行校验,等待原委托撤单成功后,由新单校验处检验) ////if (modifyType != 2) //{ //if (hkModifyOrder.OrderAmount != entrusInfo.EntrustAmount) //{ // if (entrusInfo.BuySellTypeID == (int)Types.TransactionDirection.Buying) // { // reust = PO_HoldValidate_Buy(ref strMessage, entrusInfo, request); // } // else // { // reust = PO_HoldValidate_Sell(ref strMessage, entrusInfo, request); // } // if (!reust) // { // return false; // } //} ////} //不考虑持仓量,只考虑委托最小单位的验证 HKModifyStockMinVolumeOfBusinessCommand minVolume = new HKModifyStockMinVolumeOfBusinessCommand(BreedClassID); reust = minVolume.Validate(request, ref strMessage); if (!reust) { return(false); } #endregion return(true); }
public override bool Validate(HKOrderRequest request, ref string strMessage) { string errMsg = "港股最小单位检验失败!"; string errCode = "GT-1250"; int unitID = (int)request.OrderUnitType; int tradeWayID = (int)request.BuySell; if (Utils.IsNullOrEmpty(MinVolumeOfBusinessList)) { strMessage = errCode + ":" + errMsg; return(false); } //======update 2009-11-08 李健华====== //港股只有手对股的转换,这里特殊处理,而进入此方法后的验证单位和量都转换成了股单位, //而对应的规则表(XH_MinVolumeOfBusiness表)中只有手的转换,因此这里要特殊转换 //判断是否包含有股的转换 ,没有就自行模拟加入 bool isThigh = false; List <ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness> minVolumesList = new List <ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness>(MinVolumeOfBusinessList); //minVolumesList = new List<ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness>(MinVolumeOfBusinessList); // minVolumesList =MinVolumeOfBusinessList; foreach (var item in MinVolumeOfBusinessList) { if (item.UnitID == (int)CommonObject.Types.UnitType.Thigh) { isThigh = true; break; } } //判断是否包含有股的转换 ,没有就自行模拟加入 if (!isThigh) { HK_Commodity hkComm = MCService.HKTradeRulesProxy.GetHKCommodityByCommodityCode(request.Code); ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness itembuy = new ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness(); itembuy.UnitID = (int)CommonObject.Types.UnitType.Thigh; itembuy.VolumeOfBusiness = hkComm.PerHandThighOrShare; itembuy.TradeWayID = (int)CommonObject.Types.TransactionDirection.Buying; minVolumesList.Add(itembuy); ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness itemSell = new ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness(); itemSell.UnitID = (int)CommonObject.Types.UnitType.Thigh; itemSell.VolumeOfBusiness = hkComm.PerHandThighOrShare; itemSell.TradeWayID = (int)CommonObject.Types.TransactionDirection.Selling; minVolumesList.Add(itemSell); } var minVolumes = from minVolume in minVolumesList where minVolume.UnitID.Value == unitID && minVolume.TradeWayID.Value == tradeWayID select minVolume; //当此品种没有此交易单位时检验不通过。如权证 下单80股则检验失败(单位只有手和份) if (minVolumes.Count() == 0) { strMessage = errCode + ":" + errMsg; return(false); } //================== //if (request.BuySell == CommonObject.Types.TransactionDirection.Buying) //{ foreach (ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness volume in minVolumes) { if ((int)request.OrderUnitType == volume.UnitID) { if (request.OrderAmount < volume.VolumeOfBusiness.Value || (request.OrderAmount % volume.VolumeOfBusiness.Value != 0)) { strMessage = errCode + ":" + errMsg; return(false); } } } #region 目前只验证所有的改单不分卖买验证,其他的都作为下单后验证 //} ////卖的话需要进行零股处理 //else //{ // //委托单位转换为计价单位 // decimal scale = MCService.GetTradeUnitScale(CommonObject.Types.BreedClassTypeEnum.HKStock, request.Code, request.OrderUnitType); // var amount = (decimal)request.OrderAmount * scale; // //持仓单位(默认为撮合单位)转为计价单位 // decimal scale2 = MCService.GetMatchUnitScale(CommonObject.Types.BreedClassTypeEnum.HKStock, request.Code); // var position = m_Position * scale2; // if (amount > position) // { // strMessage = errCode + ":" + "超过可用持仓"; // return false; // } // //港股最小单位零股检验 // foreach (ReckoningCounter.DAL.SpotTradingDevolveService.XH_MinVolumeOfBusiness volume in minVolumes) // { // if ((int)request.OrderUnitType == volume.UnitID) // { // if (request.OrderAmount < volume.VolumeOfBusiness.Value || // (request.OrderAmount % volume.VolumeOfBusiness.Value != 0)) // { // if (amount != position) // { // strMessage = errCode + ":" + errMsg; // return false; // } // } // } // } //} #endregion return(true); }
/// <summary> /// 买持仓检查 /// </summary> /// <param name="strMessage"></param> /// <param name="hkEntrustInfo"></param> /// <param name="request"></param> /// <returns></returns> private bool PO_HoldValidate_Buy(ref string strMessage, HK_TodayEntrustInfo hkEntrustInfo, HKOrderRequest request) { bool result = false; strMessage = ""; int position = 0; decimal freezeAmount = 0; //var ahtMemory = MemoryDataManager.HKHoldMemoryList.GetByAccountHoldLogoId(HoldingAccountId); //if (ahtMemory == null) //{ var ahtMemory = HKCommonLogic.GetHoldMemoryTable(hkEntrustInfo.HoldAccount, hkEntrustInfo.Code, hkEntrustInfo.CurrencyTypeID); //} if (ahtMemory != null && ahtMemory.Data != null) { var aht = ahtMemory.Data; position = Convert.ToInt32(aht.AvailableAmount); freezeAmount = aht.FreezeAmount; } else { position = 0; freezeAmount = 0; } HKStockMinVolumeOfBusinessCommand command = new HKStockMinVolumeOfBusinessCommand(BreedClassID, position); result = command.Validate(request, ref strMessage); // if (ValidateCenter.ValidateHKMinVolumeOfBusiness(request, position, ref strMessage)) if (result) { //获取持仓限制 Decimal pLimit = MCService.GetPositionLimit(request.Code, CommonObject.Types.BreedClassTypeEnum.HKStock).PositionValue; //可用持仓+冻结量+委托量<持仓限制 //这里是改单,所以要把之前的委托减去 result = pLimit >= position + freezeAmount + Convert.ToDecimal(request.OrderAmount - hkEntrustInfo.EntrustAmount); if (!result) { strMessage = "GT-2419:[港股改单委托验证]可用持仓+冻结量+委托量<持仓限制--港股改单委托失败"; } } else { strMessage += "--港股改单委托失败"; } //成功时需要清空错误信息。 if (result) { strMessage = ""; } return(result); }
public LocalHKStockValidater(HKOrderRequest request) { this.request = request; }
/// <summary> /// 构造函数 /// </summary> public HkTodayEntrustEx(HKOrderRequest request) { OriginalRequest = request; }
/// <summary> /// 当原始委托撤单清算完毕后,由此方法进行后继处理 /// 生成新的委托进行下单,并修改原始委托相关信息 /// </summary> /// <param name="request"></param> public void ProcessType3NewOrder(HKModifyOrderRequest request) { string desc = "M<---——ModifyOrderProcessor.ProcessType3NewOrder类型3改单——原始委托撤单清算完毕,生成新的委托下单,改单对象" + request; LogHelper.WriteDebug(desc); HK_TodayEntrustInfo tet = HKDataAccess.GetTodayEntrustTable(request.EntrustNubmer); string strMessage = ""; OrderResponse res = null; HKModifyOrderPushBack pushBack = new HKModifyOrderPushBack(); pushBack.OriginalRequestNumber = request.EntrustNubmer; pushBack.TradeID = request.TraderId; pushBack.CallbackChannlId = request.ChannelID; //计算出需要下的量 float amount = request.OrderAmount - tet.TradeAmount; //如果成交量已经大于等于当前改单量,那么无法再进行改单操作,改单失败 if (amount <= 0) { string format = "GT-2456:[港股改单委托]当前委托已成交数量{0}大于等于改单量{1}"; strMessage = string.Format(format, tet.TradeAmount, request.OrderAmount); LogHelper.WriteDebug("M<---——ModifyOrderProcessor.ProcessType3NewOrder类型3改单失败" + request + "Message=" + strMessage); pushBack.Message = strMessage; pushBack.IsSuccess = false; //将改单结果推给前台 CounterOrderService.Instance.AcceptHKModifyOrder(pushBack); //更新改单委托记录表的信息 request.Message = strMessage; HKDataAccess.UpdateModifyOrderRequest(request); } else { HKOrderRequest newRequest = CreateNewType3Request(request, tet, amount); res = OrderAccepterService.Service.DoHKOrder(newRequest); pushBack.NewRequestNumber = res.OrderId; pushBack.Message = res.OrderMessage; string txtMsg = ""; if (res.IsSuccess) { txtMsg = "类型3改单成功"; //更新改单后成功下单的委托单,--更新是一笔改单下单委托,和原来被改单的委托单号 HKDataAccess.UpdateEntrustModifyOrderNumber(res.OrderId, tet.EntrustNumber); //记录成功改单委托记录明细,方便查询和关联查询 HKDataAccess.AddModifyOrderSuccessDatils(res.OrderId, tet.EntrustNumber, 3); } else { string desc2 = "M<---——ModifyOrderProcessor.ProcessType3NewOrder类型3改单——生成新的委托下单失败,改单对象" + request + "Message=" + res.OrderMessage; LogHelper.WriteDebug(desc2); txtMsg = "GT-2457:类型3改单生成新的委托下单失败" + res.OrderMessage; //更新改单委托记录表的信息 request.Message = txtMsg; HKDataAccess.UpdateModifyOrderRequest(request); } //将改单结果推给前台 CounterOrderService.Instance.AcceptHKModifyOrder(pushBack); ////修改原始委托信息 //tet.ModifyOrderNumber = request.EntrustNubmer; //tet.IsModifyOrder = true; //HKDataAccess.UpdateEntrustTable(tet); //request.ModifyOrderDateTime = DateTime.Now; //=====add 李健华 2009-11-07========= //则更新原始委托单信息 HKDataAccess.UpdateEntrustOrderMessage(tet.EntrustNumber, txtMsg); //=========== } DeleteType3Reqeust(request.EntrustNubmer); }