/// <summary> /// 3.买一卖一百分比 /// </summary> /// <param name="request"></param> /// <returns></returns> private bool CheckType3(StockOrderRequest request, HighLowRange highLowRange) { decimal highRange = highLowRange.HighRange; decimal lowRange = highLowRange.LowRange; IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); HqExData data = service.GetStockHqData(request.Code); HqExData exData = data; HqData hqData = exData.HqData; float b1 = hqData.Buyprice1; decimal buy1 = (decimal)b1; float s1 = hqData.Sellprice1; decimal sell1 = (decimal)s1; decimal high = sell1 * highRange; decimal low = buy1 * lowRange; decimal orderPrice = (decimal)request.OrderPrice; if (orderPrice >= low && orderPrice <= high) { return(true); } return(false); }
/// <summary> /// 1.昨日收盘价的上下百分比 /// </summary> /// <param name="request"></param> /// <returns></returns> private bool CheckType1(StockOrderRequest request, HighLowRange highLowRange) { decimal highRange = highLowRange.HighRange; decimal lowRange = highLowRange.LowRange; IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); HqExData data = service.GetStockHqData(request.Code); HqExData exData = data; float yClose = exData.YClose; decimal yestPrice = (decimal)yClose; decimal high = yestPrice * (1 + highRange); decimal low = yestPrice * (1 - lowRange); decimal orderPrice = (decimal)request.OrderPrice; if (orderPrice >= low && orderPrice <= high) { return(true); } return(false); }
/// <summary> /// 5.港股买卖价位 /// </summary> /// <param name="request"></param> /// <returns></returns> private bool CheckType5(StockOrderRequest request, HighLowRange highLowRange) { HKRange hkRange = highLowRange.HongKongRange; decimal buyHighRange = hkRange.BuyHighRange; decimal buyLowRange = hkRange.BuyLowRange; decimal sellHighRange = hkRange.SellHighRange; decimal sellLowRange = hkRange.SellLowRange; IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); HqExData data = service.GetStockHqData(request.Code); HqExData exData = data; HqData hqData = exData.HqData; float b1 = hqData.Buyprice1; decimal buy1 = (decimal)b1; float s1 = hqData.Sellprice1; decimal sell1 = (decimal)s1; decimal buyH = sell1; decimal buyL = MCService.HLRangeProcessor.GetHKRangeValue(request.Code, (decimal)request.OrderPrice, buy1, -buyLowRange); decimal sellH = MCService.HLRangeProcessor.GetHKRangeValue(request.Code, (decimal)request.OrderPrice, sell1, sellHighRange); decimal sellL = buy1; decimal high = 0; decimal low = 0; if (request.BuySell == Types.TransactionDirection.Buying) { low = buyL; high = buyH; } else { low = sellL; high = sellH; } decimal orderPrice = (decimal)request.OrderPrice; if (orderPrice >= low && orderPrice <= high) { return(true); } throw new NotImplementedException(); }
/// <summary> /// 检测是否停牌 /// 当获取不到行情表示停牌,当买一价、量,卖一价、量都为0时也表示停牌 /// </summary> /// <param name="errMsg"></param> /// <param name="breedType">品种类型(这里是因为这里两种获取的行情实体方法有区别)</param> /// <returns></returns> private bool CheckStopTrading(ref string errMsg, Types.BreedClassTypeEnum breedType) { errMsg = "当前交易商品" + code + "可能停牌,委托无效。"; string errCode = "GT-1206"; errMsg = errCode + ":" + errMsg; IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); switch (breedType) { case Types.BreedClassTypeEnum.Stock: break; case Types.BreedClassTypeEnum.CommodityFuture: var hqdata = service.GetMercantileFutData(code); if (hqdata == null) { return(false); } if (hqdata.Buyprice1 == 0 && hqdata.Sellprice1 == 0 && hqdata.Buyvol1 == 0 && hqdata.Sellvol1 == 0) { return(false); } break; case Types.BreedClassTypeEnum.StockIndexFuture: var futdata = service.GetFutData(code); if (futdata == null) { return(false); } if (futdata.Buyprice1 == 0 && futdata.Sellprice1 == 0 && futdata.Buyvol1 == 0 && futdata.Sellvol1 == 0) { return(false); } break; case Types.BreedClassTypeEnum.HKStock: break; default: break; } return(true); }
/// <summary> /// 检测是否停牌,如果没有停牌,代表校验通过 /// 当获取不到行情盘前数据表示停牌,当行情盘前数据标识时为停牌则为停牌 /// </summary> /// <param name="errMsg"></param> /// <returns></returns> private bool CheckStopTrading(ref string errMsg) { errMsg = "当前交易股票" + request.Code + "可能停牌,委托无效。"; string errCode = "GT-1206"; errMsg = errCode + ":" + errMsg; #region 旧逻辑,港股要以静态数据来判断 //IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); //VTHKStockData hqdata = service.GetHKStockData(request.Code); //if (hqdata == null) // return false; //HKStock hqExData = hqdata.OriginalData; //if (hqExData == null) // return false; //if (hqExData.Buyprice1 == 0 && hqExData.Sellprice1 == 0 && hqExData.Buyvol1 == 0 && hqExData.Sellvol1 == 0) // return false; #endregion #region 新逻辑 //读行情组件静态信息列表 IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); HKStaticData hqdata = service.GetHKPreMarketData(request.Code); if (hqdata == null) { hqdata = service.GetHKPreMarketData(request.Code); } if (hqdata == null) { hqdata = service.GetHKPreMarketData(request.Code); } if (hqdata == null) { errMsg = errCode + ":" + "当前交易股票" + request.Code + "获取不到行情可能停牌,委托无效。"; return(false); } //如果停牌验证不通过 if (hqdata.SuspensionFlag == true) { return(false); } #endregion errMsg = ""; return(true); }
/// <summary> /// 处理交割月合约保证金 /// </summary> /// <param name="code">合约代码</param> /// <param name="compareDate">要比较的日期</param> /// <param name="breedClassID">合约代码所属品种类型</param> /// <returns>保证金比例</returns> private static decimal ProcessDeliveryMonth(string code, DateTime compareDate, int breedClassID) { string errCode = "GT-8482"; string errMsg = "无法根据期货商品代码获取其对应的保证金比例。"; IList <QH_CFBailScaleValue> values = GetBailScaleValues(code, breedClassID); if (values == null) { throw new VTException(errCode, errMsg); } //如果是过期合约不用获取行情的持仓量,这是为了盘前检查,因为交割月的比例计算没有用到行情持仓量 //持仓量----这里为了不用修改后面的代码设置如果合约是过期时直接给予市场持仓量为最大值,这是为了盘前检查时要计算一些强制平仓过期合约而设置 //因为过期后的合约直接取交割月的其中一个比例,而这里设置这个持仓量是为了不知道此代码所设置的保证金比例计算方式是以天计算还是双边、单边计算 decimal openInterest = int.MaxValue; if (!FutureService.CheckQHContractIsExpired(code)) { IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); //FutData futData = service.GetFutData(code); MerFutData merFutData = service.GetMercantileFutData(code); if (merFutData == null) { errMsg = "处理交割月合约保证金时无法获取行情。"; throw new VTException(errCode, errMsg); } //持仓量 openInterest = (decimal)merFutData.OpenInterest; } Types.QHCFPositionMonthType monthType = Types.QHCFPositionMonthType.OnDelivery; IList <QH_CFBailScaleValue> scaleValues = FindScaleValuesByMonthType(values, monthType); if (scaleValues.Count != 0) { return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID)); } return(-1); }
/// <summary> /// 处理交割月合约持仓限制 /// </summary> /// <param name="code">合约代码</param> /// <param name="positionValueType">持仓限制类型</param> /// <returns>持仓限制</returns> private static PositionLimitValueInfo ProcessDeliveryMonth(string code, out Types.QHPositionValueType positionValueType) { string errCode = "GT-8492"; string errMsg = "无法根据商品期货商品代码获取其对应的持仓限制。"; //根据合约代码获取其持仓限制列表 IList <QH_PositionLimitValue> values = GetPositionLimitValues(code); if (values == null) { throw new VTException(errCode, errMsg); } #region 获取行情持仓量 IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); //FutData futData = service.GetFutData(code); MerFutData merFutData = service.GetMercantileFutData(code); if (merFutData == null) { errMsg = "处理交割月合约保证金时无法获取行情-持仓限制。"; throw new VTException(errCode, errMsg); } //持仓量 decimal openInterest = (decimal)merFutData.OpenInterest; LogHelper.WriteDebug("交割月份的合约当前获取到" + code + "行情持仓量:" + openInterest); #endregion #region 过滤所属持仓限制类型记录 Types.QHCFPositionMonthType monthType = Types.QHCFPositionMonthType.OnDelivery; IList <QH_PositionLimitValue> limitValues = FindLimitValuesByMonthType(values, monthType); #endregion positionValueType = Types.QHPositionValueType.Scales; if (limitValues.Count != 0) { return(GetLimitByBailType(limitValues, openInterest, out positionValueType)); } throw new VTException(errCode, errMsg); // return -1; }
/// <summary> /// 读取交易规则及基础数据 /// </summary> private static void DoBaseData() { //已经在ScheduleManger中初始化 //MCService.CommonPara.Reset(); //MCService.CommonPara.Initialize(); LogHelper.WriteInfo("------------证券开市处理-DoBaseData"); try { MCService.Reset(); AccountManager.Instance.Reset(); #region old code 注释 --李健华 2010-06-09 ////交易员工厂封装类进行重置 //VTTradersFactory.Reset(); //VTTradersFactory.GetStockTraders(); //VTTradersFactory.GetFutureTraders(); #endregion RealTimeMarketUtil.GetInstance().Reset(); LocalCommonValidater.Reset(); #region ===回推故障数据导入 Create by:李健华 Create date:2009-08-12=== FailureRecoveryFactory.XHReaderToDB(); #endregion ===回推故障数据导入 End=== var rescueManager = RescueManager.Instance; LogHelper.WriteInfo("------------完成证券开市处理-DoBaseData"); } catch (Exception ex) { LogHelper.WriteError(ex.ToString(), ex); LogHelper.WriteInfo("------------证券开市处理失败-DoBaseData"); } }
/// <summary> /// 检测是否停牌,如果没有停牌,代表校验通过 /// 当获取不到行情表示停牌,当买一价、量,卖一价、量都为0时也表示停牌 /// </summary> /// <param name="errMsg"></param> /// <returns></returns> private bool CheckStopTrading(ref string errMsg) { errMsg = "当前交易股票" + request.Code + "可能停牌,委托无效。"; string errCode = "GT-1206"; errMsg = errCode + ":" + errMsg; IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); var hqdata = service.GetStockHqData(request.Code); if (hqdata == null) { return(false); } var hqExData = hqdata; if (hqExData == null) { return(false); } var hqData = hqExData.HqData; if (hqData == null) { return(false); } if (hqData.Buyprice1 == 0 && hqData.Sellprice1 == 0 && hqData.Buyvol1 == 0 && hqData.Sellvol1 == 0) { return(false); } errMsg = ""; return(true); }
/// <summary> /// 6.最近成交价上下各多少元 /// </summary> /// <param name="request"></param> /// <returns></returns> private bool CheckType6(StockOrderRequest request, HighLowRange highLowRange) { decimal highRange = highLowRange.HighRange; decimal lowRange = highLowRange.LowRange; IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); HqExData data = service.GetStockHqData(request.Code); HqExData exData = data; float rPrice = exData.LastVolume; decimal recentPrice = (decimal)rPrice; decimal high = recentPrice + highRange; decimal low = recentPrice - lowRange; decimal orderPrice = (decimal)request.OrderPrice; if (orderPrice >= low && orderPrice <= high) { return(true); } return(false); }
/// <summary> /// 处理费交割月份的合约 /// </summary> /// <param name="code">合约代码</param> /// <param name="year">合约年</param> /// <param name="month">合约月</param> /// <param name="compareDate">要比较的日期</param> /// <param name="breedClassID">合约代码所属品种类型</param> /// <returns>保证金比例</returns> private static decimal ProcessNonDeliveryMonth(string code, int year, int month, DateTime compareDate, int breedClassID) { string errCode = "GT-8482"; string errMsg = "无法根据期货商品代码获取其对应的保证金比例。"; IList <QH_CFBailScaleValue> values = GetBailScaleValues(code, breedClassID); if (values == null || values.Count <= 0) { throw new VTException(errCode, errMsg); } IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); //FutData futData = service.GetFutData(code); MerFutData merFutData = service.GetMercantileFutData(code); if (merFutData == null) { errMsg = "处理交割月合约保证金时无法获取行情。"; throw new VTException(errCode, errMsg); } //持仓量 decimal openInterest = (decimal)merFutData.OpenInterest; //判断当前月份是那种交割月份类型 Types.QHCFPositionMonthType monthType = FutureService.CheckMonthType(year, month, compareDate); IList <QH_CFBailScaleValue> scaleValues; #region 前三个月交割月份 //如果是前三 if (monthType == Types.QHCFPositionMonthType.OnDeliAgoThreeMonth) { scaleValues = FindScaleValuesByMonthType(values, monthType); //是前三 if (scaleValues.Count > 0) { return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID)); } //否则就是一般月份 scaleValues = FindScaleValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth); if (scaleValues.Count > 0) { return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID)); } } #endregion #region 前二 //如果是前二 if (monthType == Types.QHCFPositionMonthType.OnDeliAgoTwoMonth) { scaleValues = FindScaleValuesByMonthType(values, monthType); //是前二 if (scaleValues.Count > 0) { return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID)); } //否则就是一般月份 scaleValues = FindScaleValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth); if (scaleValues.Count > 0) { return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID)); } } #endregion #region 前一 //如果是前一 if (monthType == Types.QHCFPositionMonthType.OnDeliAgoMonth) { scaleValues = FindScaleValuesByMonthType(values, monthType); //是前一 if (scaleValues.Count > 0) { return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID)); } //否则就是一般月份 scaleValues = FindScaleValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth); if (scaleValues.Count > 0) { return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID)); } } #endregion #region 一般月份 //如果是一般月份 if (monthType == Types.QHCFPositionMonthType.GeneralMonth) { scaleValues = FindScaleValuesByMonthType(values, monthType); //是一般月份 if (scaleValues.Count > 0) { return(GetScaleByBailType(scaleValues, openInterest, compareDate, breedClassID)); } } #endregion #region 最低保证金 QH_SIFBail sifBail = MCService.FuturesTradeRules.GetSIFBailByBreedClassID(breedClassID); if (sifBail == null) { LogHelper.WriteError("Debug_Test_Bail_ProcessNonDeliveryMonth_01:无法获取最低交易保证金比例", new Exception("")); return(-1); } else { LogHelper.WriteDebug("Debug_Test_Bail_ProcessNonDeliveryMonth_02:无对应的保证金比例区间范围值获取最低交易保证金比例" + sifBail.BailScale); return(sifBail.BailScale); } #endregion //return -1; }
/// <summary> /// 处理非交割月份的合约 /// </summary> /// <param name="code">合约代码</param> /// <param name="year">合约年</param> /// <param name="month">合约月</param> /// <param name="positionValueType">持仓限制类型</param> /// <returns>保证金比例</returns> private static PositionLimitValueInfo ProcessNonDeliveryMonth(string code, int year, int month, out Types.QHPositionValueType positionValueType) { string errCode = "GT-8492"; string errMsg = "无法根据期货商品代码获取其对应的持仓限制。"; IList <QH_PositionLimitValue> values = GetPositionLimitValues(code); if (values == null) { throw new VTException(errCode, errMsg); } IRealtimeMarketService service = RealTimeMarketUtil.GetRealMarketService(); //RealtimeMarketServiceFactory.GetService(); //FutData futData = service.GetFutData(code); MerFutData merFutData = service.GetMercantileFutData(code); if (merFutData == null) { errMsg = "处理交割月合约保证金时无法获取行情-持仓限制。"; throw new VTException(errCode, errMsg); } //持仓量 decimal openInterest = (decimal)merFutData.OpenInterest; LogHelper.WriteDebug("非交割月份的合约当前获取到" + code + "行情持仓量:" + openInterest); //判断当前月份是那种交割月份类型 Types.QHCFPositionMonthType monthType = FutureService.CheckMonthType(year, month, DateTime.Now); IList <QH_PositionLimitValue> limitValues; positionValueType = Types.QHPositionValueType.Scales; #region 交割月份前三个月 //如果是前三 if (monthType == Types.QHCFPositionMonthType.OnDeliAgoThreeMonth) { limitValues = FindLimitValuesByMonthType(values, monthType); //是前三 if (limitValues.Count > 0) { return(GetLimitByBailType(limitValues, openInterest, out positionValueType)); } errMsg = "代码" + code + " 无法获取交割前三个月的对应的持仓限制列表参数正在以一般月份查询。"; LogHelper.WriteDebug(errCode + errMsg); //否则就是一般月份 limitValues = FindLimitValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth); if (limitValues.Count > 0) { PositionLimitValueInfo generOnThree = GetLimitByBailType(limitValues, openInterest, out positionValueType); if (generOnThree.PositionValue == -1) { generOnThree.IsNoComputer = true; } return(generOnThree); } errMsg = "代码" + code + " 无法获取交割月份前三个月的一般月份的对应的持仓限制列表参数。"; LogHelper.WriteDebug(errCode + errMsg); } #endregion #region 交割月份前二个月 //如果是前二 if (monthType == Types.QHCFPositionMonthType.OnDeliAgoTwoMonth) { limitValues = FindLimitValuesByMonthType(values, monthType); //是前二 if (limitValues.Count > 0) { return(GetLimitByBailType(limitValues, openInterest, out positionValueType)); } errMsg = "代码" + code + " 无法获取交割前两个月的对应的持仓限制列表参数。"; LogHelper.WriteDebug(errCode + errMsg); //否则就是一般月份 limitValues = FindLimitValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth); if (limitValues.Count > 0) { PositionLimitValueInfo generOnDeliAgo = GetLimitByBailType(limitValues, openInterest, out positionValueType); if (generOnDeliAgo.PositionValue == -1) { generOnDeliAgo.IsNoComputer = true; } return(generOnDeliAgo); } errMsg = "代码" + code + " 无法获取交割月份前两个月的一般月份的对应的持仓限制列表参数。"; LogHelper.WriteDebug(errCode + errMsg); } #endregion #region 交割月份前一个月 //如果是前一 if (monthType == Types.QHCFPositionMonthType.OnDeliAgoMonth) { limitValues = FindLimitValuesByMonthType(values, monthType); //是前一 if (limitValues.Count > 0) { return(GetLimitByBailType(limitValues, openInterest, out positionValueType)); } errMsg = "代码" + code + " 无法获取交割前一个月的对应的持仓限制列表参数正在以一般月份查询。"; LogHelper.WriteDebug(errCode + errMsg); //否则就是一般月份 limitValues = FindLimitValuesByMonthType(values, Types.QHCFPositionMonthType.GeneralMonth); if (limitValues.Count > 0) { PositionLimitValueInfo generOnDeli = GetLimitByBailType(limitValues, openInterest, out positionValueType); if (generOnDeli.PositionValue == -1) { generOnDeli.IsNoComputer = true; } return(generOnDeli); } errMsg = "代码" + code + " 无法获取交割月份前一个月的一般月份的对应的持仓限制列表参数。"; LogHelper.WriteDebug(errCode + errMsg); } #endregion #region 交割月份一般月份 //如果是一般月份 if (monthType == Types.QHCFPositionMonthType.GeneralMonth) { limitValues = FindLimitValuesByMonthType(values, monthType); //是一般月份 if (limitValues.Count > 0) { PositionLimitValueInfo gener = GetLimitByBailType(limitValues, openInterest, out positionValueType); if (gener.PositionValue == -1) { gener.IsNoComputer = true; } return(gener); } errMsg = "代码" + code + " 无法获取一般月份的对应的持仓限制列表参数。"; LogHelper.WriteDebug(errCode + errMsg); } #endregion PositionLimitValueInfo info = new PositionLimitValueInfo(); info.PositionValue = -1; info.IsMinMultiple = false; info.MinMultipleValue = 0; //return -1; return(info); }
/// <summary> /// 商品期货强行平仓 /// Create by:董鹏 /// Create Date:2010-02-04 /// </summary> /// <param name="orderAccepter">委托接收对象</param> /// <param name="holdTable">持仓实体</param> /// <param name="price">委托价格</param> /// <param name="amount">委托数量</param> /// <param name="isExpiredContract">是否是过期的合约需要平仓</param> private void CloseCommoditiesContract(OrderAccepter orderAccepter, QH_HoldAccountTableInfo holdTable, float price, float amount, Types.QHForcedCloseType closeType, Entity.Contants.Types.FutureOpenCloseType closeType2) { if (holdTable == null) { return; } if (holdTable.HistoryHoldAmount == 0 && closeType2 == ReckoningCounter.Entity.Contants.Types.FutureOpenCloseType.ClosePosition) { return; } if (holdTable.TodayHoldAmount == 0 && closeType2 == ReckoningCounter.Entity.Contants.Types.FutureOpenCloseType.CloseTodayPosition) { return; } MercantileFuturesOrderRequest2 request = null; request = new MercantileFuturesOrderRequest2(); string type = ""; switch (closeType) { case Types.QHForcedCloseType.Expired: // request.IsExpiredContract = true; type = "过期合约持仓检查平仓"; break; case Types.QHForcedCloseType.CapitalCheck: //request.IsCapitalCheckContract = true; type = "资金检查平仓"; break; case Types.QHForcedCloseType.OverHoldLimit: //request.IsOverHoldLimitContract = true; type = "持仓限制检查平仓"; break; case Types.QHForcedCloseType.NotModMinUnit: //request.IsNotModMinUnitContract = true; type = "最小交割单位整数倍持仓检查平仓"; break; } request.QHForcedCloseType = closeType; //盘前检查强行平仓类型 request.IsForcedCloseOrder = true; //是否盘前检查强行平仓 //{ // request = new MercantileFuturesOrderRequest2 { IsExpiredContract = true, IsCapitalCheckContract = false }; //} //else //{ // request = new MercantileFuturesOrderRequest2 { IsExpiredContract = false, IsCapitalCheckContract = true }; //} var buySellType = holdTable.BuySellTypeId == (int)Types.TransactionDirection.Buying ? Types.TransactionDirection.Selling : Types.TransactionDirection.Buying; request.BuySell = buySellType; request.Code = holdTable.Contract; request.FundAccountId = capitalAccount.UserAccountDistributeLogo; request.OpenCloseType = closeType2; request.OrderAmount = amount;//(float)holdTable.HistoryHoldAmount; //和刘丹确认过,不是过期合约平仓或者价格为0时,取当日的涨停价或跌停价报盘,买平用涨停价,卖平用跌停价,add by 董鹏 2010-02-23 //2010-04-02 和刘丹、苏婷再次讨论,定为先取行情最新价,若取不到在使用涨跌停价 update by 董鹏 2010-04-02 if (closeType != Types.QHForcedCloseType.Expired || price == 0) { string errMsg; int errcount = 0; //获取行情最新成交价 MarketDataLevel marketData = null; while (marketData == null) { marketData = RealTimeMarketUtil.GetInstance().GetLastPriceByCode(holdTable.Contract, (int)Types.BreedClassTypeEnum.CommodityFuture, out errMsg); errcount++; if (errcount > 10) { LogHelper.WriteDebug("期货强行平仓,无法获取到行情最新成交价。CloseCommoditiesContract"); break; } if (marketData == null) { Thread.Sleep(10000); } } if (marketData != null && marketData.LastPrice != 0) { price = (float)marketData.LastPrice; } else { //取不到行情成交价,取涨跌停板价 HighLowRangeValue hlValue = null; while (hlValue == null) { hlValue = MCService.HLRangeProcessor.GetHighLowRangeValueByCommodityCode(holdTable.Contract, 0); errcount++; if (errcount > 10) { LogHelper.WriteDebug("期货强行平仓,无法获取到涨跌停板价格。CloseCommoditiesContract"); return; } if (hlValue == null) { Thread.Sleep(10000); } } price = holdTable.BuySellTypeId == (int)Types.TransactionDirection.Buying ? (float)hlValue.HighRangeValue : (float)hlValue.LowRangeValue; } } request.OrderPrice = price; request.OrderUnitType = Types.UnitType.Hand; request.OrderWay = Entity.Contants.Types.OrderPriceType.OPTLimited; string format = "FutureDayChecker开盘持仓检查强制平仓[UserAccountDistributeLogo={0},AccountHoldLogoId={1},Code={2}, Price={3}, 平仓类型={4}]-委托信息:" + request; string msg = string.Format(format, holdTable.UserAccountDistributeLogo, holdTable.AccountHoldLogoId, holdTable.Contract, price, type); LogHelper.WriteDebug(msg + holdTable); UA_UserAccountAllocationTableDal ua_UserAccountAllocationTableDal = new UA_UserAccountAllocationTableDal(); //设置为其所属的交易员 var userAccountAllocationTable = ua_UserAccountAllocationTableDal.GetModel(capitalAccount.UserAccountDistributeLogo); if (userAccountAllocationTable == null) { string msg2 = "开盘检查强行平仓失败!无法获取资金账户信息,ID=" + capitalAccount.UserAccountDistributeLogo; LogHelper.WriteInfo(msg2); return; } UA_UserBasicInformationTableDal ua_UserBasicInformationTableDal = new UA_UserBasicInformationTableDal(); var user = ua_UserBasicInformationTableDal.GetModel(userAccountAllocationTable.UserID); if (user == null) { string msg3 = "开盘检查强行平仓失败!无法获取交易员信息,UserID=" + userAccountAllocationTable.UserID; LogHelper.WriteInfo(msg3); return; } request.TraderId = user.UserID; request.TraderPassword = user.Password; orderAccepter.DoMercantileFuturesOrder(request); }