/// <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> /// 商品期货强行平仓 /// 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); }