public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!this.IsConnected) { this.EmitError(1, "The current instrument provider not connected."); return; } string[] markets = supportMarkets.Split(','); //是否包含交易市场 if (request.ContainsField(0xcf) && markets.Contains(request.SecurityExchange)) { List <GMSDK.Instrument> gskInsts = _md.GetInstruments(request.SecurityExchange, this.securityTypeFilter, 0); foreach (GMSDK.Instrument gskInst in gskInsts) { FIXSecurityDefinition definition = new FIXSecurityDefinition(request.SecurityReqID, request.SecurityReqID, 4); string[] ss = gskInst.symbol.Split('.'); definition.SecurityExchange = ss[0]; //市场 definition.SecurityID = ss[1]; //代码 definition.SecurityIDSource = "8"; // 8=Exchange Symbol definition.Symbol = gskInst.symbol; switch (gskInst.sec_type) { case 1: definition.SecurityType = "CS"; //股票 break; case 2: definition.SecurityType = "MF"; //基金(Mutual Fund,共同基金) break; case 3: definition.SecurityType = "IDX"; //指数 break; case 4: definition.SecurityType = "FUT"; //期货 break; } //definition.SecuritySubType = symbol.StockType.ToString(); definition.SecurityDesc = gskInst.sec_name; if (definition.SecurityType == "FUT") { definition.ContractMultiplier = gskInst.multiplier; //合约乘数 definition.PctAtRisk = gskInst.margin_ratio; //保证金比例 definition.TickSize = gskInst.price_tick; //价格最小变动单位 } definition.TotNoRelatedSym = gskInsts.Count; if (this.SecurityDefinition != null) { this.SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { EmitError(-1, -1, "交易没有连接,无法获取合约列表"); tdlog.Error("交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List<CZQThostFtdcInstrumentField> list = new List<CZQThostFtdcInstrumentField>(); foreach (CZQThostFtdcInstrumentField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (securityType == GetSecurityType(inst)) { ++flag; } } if (3==flag) { list.Add(inst); } } #endregion list.Sort(SortCZQThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0==list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (CZQThostFtdcInstrumentField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { string securityType2 = GetSecurityType(inst); definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.PriceTick; if (x>0.0001) { int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); definition.AddField(EFIXField.TickSize, inst.PriceTick); } } definition.AddField(EFIXField.Symbol, GetYahooSymbol(inst.InstrumentID, inst.ExchangeID)); definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.InstrumentName); definition.AddField(EFIXField.Factor, (double)inst.VolumeMultiple); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { this.EmitError(-1, -1, "交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List <CThostFtdcInstrumentField> list = new List <CThostFtdcInstrumentField>(); foreach (CThostFtdcInstrumentField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.Future == securityType) { if (TThostFtdcProductClassType.Futures == inst.ProductClass) { ++flag; } } else if (FIXSecurityType.MultiLegInstrument == securityType)//理解上是否有问题 { if (TThostFtdcProductClassType.Combination == inst.ProductClass) { ++flag; } } else if (FIXSecurityType.Option == securityType) { if (TThostFtdcProductClassType.Options == inst.ProductClass) { ++flag; } } } if (3 == flag) { list.Add(inst); } } #endregion list.Sort(SortCThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (CThostFtdcInstrumentField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { string securityType2; switch (inst.ProductClass) { case TThostFtdcProductClassType.Futures: securityType2 = FIXSecurityType.Future; break; case TThostFtdcProductClassType.Combination: securityType2 = FIXSecurityType.MultiLegInstrument; //此处是否理解上有不同 break; case TThostFtdcProductClassType.Options: securityType2 = FIXSecurityType.Option; break; default: securityType2 = FIXSecurityType.NoSecurityType; break; } definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.PriceTick; int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); } definition.AddField(EFIXField.Symbol, inst.InstrumentID); definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.TickSize, inst.PriceTick); definition.AddField(EFIXField.SecurityDesc, inst.InstrumentName); definition.AddField(EFIXField.MaturityDate, DateTime.ParseExact(inst.ExpireDate, "yyyyMMdd", null)); definition.AddField(EFIXField.Factor, (double)inst.VolumeMultiple); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (_dictDepthMarketData) { string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List <StructRcvReportEx> list = new List <StructRcvReportEx>(); foreach (StructRcvReport inst in _dictDepthMarketData.Values) { StructRcvReportEx ex = new StructRcvReportEx(inst); int flag = 0; if (null == symbol) { ++flag; } else if (ex.newSymbol.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (ex.yahooExchange.StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (securityType == ex.securityType) { ++flag; } } if (3 == flag) { list.Add(ex); } } #endregion list.Sort(SortCThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (StructRcvReportEx inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { definition.AddField(EFIXField.SecurityType, inst.securityType); } { //double x = inst.PriceTick; //if (x > 0.0001) //{ // int i = 0; // for (; x - (int)x != 0; ++i) // { // x = x * 10; // } // definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); // definition.AddField(EFIXField.TickSize, inst.PriceTick); //} } definition.AddField(EFIXField.Symbol, GetYahooSymbol(inst.newSymbol, inst.yahooExchange)); definition.AddField(EFIXField.SecurityExchange, inst.yahooExchange); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.RcvReport.StockName); FIXSecurityAltIDGroup group = new FIXSecurityAltIDGroup(); group.SecurityAltID = inst.RcvReport.StockCode; group.SecurityAltExchange = inst.RcvReport.MarketType; group.SecurityAltIDSource = this.Name; definition.AddGroup(group); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { EmitError(-1, -1, "交易没有连接,无法获取合约列表"); tdlog.Error("交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List<CThostFtdcInstrumentField> list = new List<CThostFtdcInstrumentField>(); foreach (CThostFtdcInstrumentField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.Future == securityType) { if (TThostFtdcProductClassType.Futures == inst.ProductClass) { ++flag; } } else if (FIXSecurityType.MultiLegInstrument == securityType)//理解上是否有问题 { if (TThostFtdcProductClassType.Combination == inst.ProductClass) { ++flag; } } else if (FIXSecurityType.Option == securityType) { if (TThostFtdcProductClassType.Options == inst.ProductClass) { ++flag; } } } if (3==flag) { list.Add(inst); } } #endregion list.Sort(SortCThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0==list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (CThostFtdcInstrumentField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { string securityType2; switch (inst.ProductClass) { case TThostFtdcProductClassType.Futures: securityType2 = FIXSecurityType.Future; break; case TThostFtdcProductClassType.Combination: securityType2 = FIXSecurityType.MultiLegInstrument;//此处是否理解上有不同 break; case TThostFtdcProductClassType.Options: securityType2 = FIXSecurityType.Option; break; default: securityType2 = FIXSecurityType.NoSecurityType; break; } definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.PriceTick; int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}",i)); } definition.AddField(EFIXField.Symbol, inst.InstrumentID); definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.TickSize, inst.PriceTick); definition.AddField(EFIXField.SecurityDesc, inst.InstrumentName); definition.AddField(EFIXField.Factor, (double)inst.VolumeMultiple); if(inst.ProductClass == TThostFtdcProductClassType.Futures||inst.ProductClass == TThostFtdcProductClassType.Options) { try { definition.AddField(EFIXField.MaturityDate, DateTime.ParseExact(inst.ExpireDate, "yyyyMMdd", CultureInfo.InvariantCulture)); } catch (Exception ex) { tdlog.Warn("合约:{0},字段内容:{1},{2}", inst.InstrumentID, inst.ExpireDate, ex.Message); } } //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { EmitError(-1, -1, "交易没有连接,无法获取合约列表"); tdlog.Error("交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List <CZQThostFtdcInstrumentField> list = new List <CZQThostFtdcInstrumentField>(); foreach (CZQThostFtdcInstrumentField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (securityType == GetSecurityType(inst)) { ++flag; } } if (3 == flag) { list.Add(inst); } } #endregion list.Sort(SortCZQThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (CZQThostFtdcInstrumentField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { string securityType2 = GetSecurityType(inst); definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.PriceTick; if (x > 0.0001) { int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); definition.AddField(EFIXField.TickSize, inst.PriceTick); } } definition.AddField(EFIXField.Symbol, GetYahooSymbol(inst.InstrumentID, inst.ExchangeID)); definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.InstrumentName); definition.AddField(EFIXField.Factor, (double)inst.VolumeMultiple); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { EmitError(-1, -1, "交易没有连接,无法获取合约列表"); tdlog.Error("交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List <CThostFtdcInstrumentField> list = new List <CThostFtdcInstrumentField>(); foreach (CThostFtdcInstrumentField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (securityType == GetSecurityType(inst)) { ++flag; } } if (3 == flag) { list.Add(inst); } } #endregion list.Sort(SortCThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (CThostFtdcInstrumentField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { string securityType2 = GetSecurityType(inst); definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.PriceTick; if (x > 0.00001) { int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); definition.AddField(EFIXField.TickSize, inst.PriceTick); } } #if CTP definition.AddField(EFIXField.Symbol, inst.InstrumentID); #elif CTPZQ definition.AddField(EFIXField.Symbol, GetYahooSymbol(inst.InstrumentID, inst.ExchangeID)); #endif definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.InstrumentName); definition.AddField(EFIXField.Factor, (double)inst.VolumeMultiple); if (inst.ProductClass == TThostFtdcProductClassType.Futures || inst.ProductClass == TThostFtdcProductClassType.Options) { try { definition.AddField(EFIXField.MaturityDate, DateTime.ParseExact(inst.ExpireDate, "yyyyMMdd", CultureInfo.InvariantCulture)); } catch (Exception ex) { tdlog.Warn("合约:{0},字段内容:{1},{2}", inst.InstrumentID, inst.ExpireDate, ex.Message); } //if (inst.ProductClass == TThostFtdcProductClassType.Options) //{ // // 支持中金所,大商所,郑商所 // var match = Regex.Match(inst.InstrumentID, @"(\d+)(-?)([CP])(-?)(\d+)"); // if (match.Success) // { // definition.AddField(EFIXField.PutOrCall, match.Groups[3].Value == "C" ? FIXPutOrCall.Call : FIXPutOrCall.Put); // definition.AddField(EFIXField.StrikePrice, double.Parse(match.Groups[5].Value)); // } //} } // 中金所仿真平台下,居然全设的是股票 var match = Regex.Match(inst.InstrumentID, @"(\d+)(-?)([CP])(-?)(\d+)"); if (match.Success) { definition.AddField(EFIXField.PutOrCall, match.Groups[3].Value == "C" ? FIXPutOrCall.Call : FIXPutOrCall.Put); definition.AddField(EFIXField.StrikePrice, double.Parse(match.Groups[5].Value)); } FIXSecurityAltIDGroup group = new FIXSecurityAltIDGroup(); group.SecurityAltID = inst.InstrumentID; group.SecurityAltExchange = inst.ExchangeID; group.SecurityAltIDSource = this.Name; definition.AddGroup(group); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { EmitError(-1, -1, "交易没有连接,无法获取合约列表"); tdlog.Error("交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List <DFITCExchangeInstrumentRtnField> list = new List <DFITCExchangeInstrumentRtnField>(); foreach (DFITCExchangeInstrumentRtnField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.Future == securityType) { if (DFITCInstrumentTypeType.COMM_TYPE == inst.instrumentType) { ++flag; } } //else if (FIXSecurityType.MultiLegInstrument == securityType)//理解上是否有问题 //{ // if (TThostFtdcProductClassType.Combination == inst.ProductClass) // { // ++flag; // } //} else if (FIXSecurityType.FutureOption == securityType) { if (DFITCInstrumentTypeType.OPT_TYPE == inst.instrumentType) { ++flag; } } } if (3 == flag) { list.Add(inst); } } #endregion #region 过滤1 List <DFITCAbiInstrumentRtnField> list1 = new List <DFITCAbiInstrumentRtnField>(); foreach (DFITCAbiInstrumentRtnField inst in _dictAbiInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.MultiLegInstrument == securityType) { ++flag; } } if (3 == flag) { list1.Add(inst); } } #endregion list.Sort(SortDFITCExchangeInstrumentRtnField); list1.Sort(SortDFITCAbiInstrumentRtnField); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count && 0 == list1.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } #region 期货 期权 foreach (DFITCExchangeInstrumentRtnField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count + list1.Count, }; { string securityType2; switch (inst.instrumentType) { case DFITCInstrumentTypeType.COMM_TYPE: securityType2 = FIXSecurityType.Future; break; case DFITCInstrumentTypeType.OPT_TYPE: securityType2 = FIXSecurityType.FutureOption; var match = Regex.Match(inst.InstrumentID, @"(\d+)(-?)([CP])(-?)(\d+)"); if (match.Success) { definition.AddField(EFIXField.PutOrCall, match.Groups[3].Value == "C" ? FIXPutOrCall.Call : FIXPutOrCall.Put); definition.AddField(EFIXField.StrikePrice, double.Parse(match.Groups[5].Value)); } break; default: securityType2 = FIXSecurityType.NoSecurityType; break; } definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.minPriceFluctuation; int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); } definition.AddField(EFIXField.Symbol, inst.InstrumentID); definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.TickSize, inst.minPriceFluctuation); definition.AddField(EFIXField.SecurityDesc, inst.VarietyName); definition.AddField(EFIXField.Factor, inst.contractMultiplier); try { definition.AddField(EFIXField.MaturityDate, DateTime.ParseExact(inst.instrumentMaturity, "yyyy.MM.dd", CultureInfo.InvariantCulture)); } catch (Exception ex) { tdlog.Warn("合约:{0},字段内容:{1},{2}", inst.InstrumentID, inst.instrumentMaturity, ex.Message); } FIXSecurityAltIDGroup group = new FIXSecurityAltIDGroup(); group.SecurityAltID = inst.InstrumentID; group.SecurityAltExchange = inst.ExchangeID; group.SecurityAltIDSource = this.Name; definition.AddGroup(group); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } #endregion #region 组合 foreach (DFITCAbiInstrumentRtnField inst in list1) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count + list1.Count, }; string securityType2 = FIXSecurityType.MultiLegInstrument; definition.AddField(EFIXField.SecurityType, securityType2); definition.AddField(EFIXField.Symbol, inst.InstrumentID); // definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY"); //Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.instrumentName); if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } #endregion } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { EmitError(-1, -1, "交易没有连接,无法获取合约列表"); tdlog.Error("交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List<CThostFtdcInstrumentField> list = new List<CThostFtdcInstrumentField>(); foreach (CThostFtdcInstrumentField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (securityType == GetSecurityType(inst)) { ++flag; } } if (3==flag) { list.Add(inst); } } #endregion list.Sort(SortCThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0==list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (CThostFtdcInstrumentField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { string securityType2 = GetSecurityType(inst); definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.PriceTick; if (x > 0.00001) { int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); definition.AddField(EFIXField.TickSize, inst.PriceTick); } } #if CTP definition.AddField(EFIXField.Symbol, inst.InstrumentID); #elif CTPZQ definition.AddField(EFIXField.Symbol, GetYahooSymbol(inst.InstrumentID, inst.ExchangeID)); #endif definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.InstrumentName); definition.AddField(EFIXField.Factor, (double)inst.VolumeMultiple); if(inst.ProductClass == TThostFtdcProductClassType.Futures||inst.ProductClass == TThostFtdcProductClassType.Options) { try { definition.AddField(EFIXField.MaturityDate, DateTime.ParseExact(inst.ExpireDate, "yyyyMMdd", CultureInfo.InvariantCulture)); } catch (Exception ex) { tdlog.Warn("合约:{0},字段内容:{1},{2}", inst.InstrumentID, inst.ExpireDate, ex.Message); } //if (inst.ProductClass == TThostFtdcProductClassType.Options) //{ // // 支持中金所,大商所,郑商所 // var match = Regex.Match(inst.InstrumentID, @"(\d+)(-?)([CP])(-?)(\d+)"); // if (match.Success) // { // definition.AddField(EFIXField.PutOrCall, match.Groups[3].Value == "C" ? FIXPutOrCall.Call : FIXPutOrCall.Put); // definition.AddField(EFIXField.StrikePrice, double.Parse(match.Groups[5].Value)); // } //} } // 中金所仿真平台下,居然全设的是股票 var match = Regex.Match(inst.InstrumentID, @"(\d+)(-?)([CP])(-?)(\d+)"); if (match.Success) { definition.AddField(EFIXField.PutOrCall, match.Groups[3].Value == "C" ? FIXPutOrCall.Call : FIXPutOrCall.Put); definition.AddField(EFIXField.StrikePrice, double.Parse(match.Groups[5].Value)); } FIXSecurityAltIDGroup group = new FIXSecurityAltIDGroup(); group.SecurityAltID = inst.InstrumentID; group.SecurityAltExchange = inst.ExchangeID; group.SecurityAltIDSource = this.Name; definition.AddGroup(group); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { this.EmitError(-1,-1,"交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List<CZQThostFtdcInstrumentField> list = new List<CZQThostFtdcInstrumentField>(); foreach (CZQThostFtdcInstrumentField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.Future == securityType) { if (TZQThostFtdcProductClassType.Futures == inst.ProductClass || TZQThostFtdcProductClassType.EFP == inst.ProductClass) { ++flag; } } else if (FIXSecurityType.MultiLegInstrument == securityType)//理解上是否有问题 { if (TZQThostFtdcProductClassType.Combination == inst.ProductClass) { ++flag; } } else if (FIXSecurityType.Option == securityType) { if (TZQThostFtdcProductClassType.Options == inst.ProductClass) { ++flag; } } else if (FIXSecurityType.CommonStock == securityType) { if (TZQThostFtdcProductClassType.StockA == inst.ProductClass || TZQThostFtdcProductClassType.StockB == inst.ProductClass) { ++flag; } } else if (FIXSecurityType.ExchangeTradedFund == securityType) { if (TZQThostFtdcProductClassType.ETF == inst.ProductClass || TZQThostFtdcProductClassType.ETFPurRed == inst.ProductClass) { ++flag; } } } if (3==flag) { list.Add(inst); } } #endregion list.Sort(SortCZQThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0==list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (CZQThostFtdcInstrumentField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { string securityType2; switch (inst.ProductClass) { case TZQThostFtdcProductClassType.Futures: securityType2 = FIXSecurityType.Future; break; case TZQThostFtdcProductClassType.Combination: securityType2 = FIXSecurityType.MultiLegInstrument;//此处是否理解上有不同 break; case TZQThostFtdcProductClassType.Options: securityType2 = FIXSecurityType.Option; break; case TZQThostFtdcProductClassType.StockA: case TZQThostFtdcProductClassType.StockB: securityType2 = GetSecurityTypeFromProductID(inst.ProductID); break; case TZQThostFtdcProductClassType.ETF: case TZQThostFtdcProductClassType.ETFPurRed: securityType2 = FIXSecurityType.ExchangeTradedFund; break; default: securityType2 = FIXSecurityType.NoSecurityType; break; } definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.PriceTick; if (x>0.0001) { int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); definition.AddField(EFIXField.TickSize, inst.PriceTick); } } definition.AddField(EFIXField.Symbol, inst.InstrumentID); definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.InstrumentName); definition.AddField(EFIXField.Factor, (double)inst.VolumeMultiple); //try //{ // definition.AddField(EFIXField.MaturityDate, DateTime.ParseExact(inst.ExpireDate, "yyyyMMdd", null)); //} //catch (System.Exception ex) //{ //} //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List <StockInfoEx> list = new List <StockInfoEx>(); foreach (StockInfoEx inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.stockinfo.szCode.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.market.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.Future == securityType) { ++flag; } } if (3 == flag) { list.Add(inst); } } #endregion list.Sort(SortStockInfoEx); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (StockInfoEx inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; definition.AddField(EFIXField.SecurityType, FIXSecurityType.Future); definition.AddField(EFIXField.Symbol, inst.stockinfo.szCode); definition.AddField(EFIXField.SecurityExchange, inst.market); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.stockinfo.szName); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!_bTdConnected) { EmitError(-1, -1, "交易没有连接,无法获取合约列表"); tdlog.Error("交易没有连接,无法获取合约列表"); return; } string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List<DFITCExchangeInstrumentRtnField> list = new List<DFITCExchangeInstrumentRtnField>(); foreach (DFITCExchangeInstrumentRtnField inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.Future == securityType) { if (DFITCInstrumentTypeType.COMM_TYPE == inst.instrumentType) { ++flag; } } //else if (FIXSecurityType.MultiLegInstrument == securityType)//理解上是否有问题 //{ // if (TThostFtdcProductClassType.Combination == inst.ProductClass) // { // ++flag; // } //} else if (FIXSecurityType.FutureOption == securityType) { if (DFITCInstrumentTypeType.OPT_TYPE == inst.instrumentType) { ++flag; } } } if (3 == flag) { list.Add(inst); } } #endregion #region 过滤1 List<DFITCAbiInstrumentRtnField> list1 = new List<DFITCAbiInstrumentRtnField>(); foreach (DFITCAbiInstrumentRtnField inst in _dictAbiInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.InstrumentID.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.ExchangeID.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.MultiLegInstrument == securityType) { ++flag; } } if (3 == flag) { list1.Add(inst); } } #endregion list.Sort(SortDFITCExchangeInstrumentRtnField); list1.Sort(SortDFITCAbiInstrumentRtnField); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count&&0==list1.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } #region 期货 期权 foreach (DFITCExchangeInstrumentRtnField inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count + list1.Count, }; { string securityType2; switch (inst.instrumentType) { case DFITCInstrumentTypeType.COMM_TYPE: securityType2 = FIXSecurityType.Future; break; case DFITCInstrumentTypeType.OPT_TYPE: securityType2 = FIXSecurityType.FutureOption; var match = Regex.Match(inst.InstrumentID, @"(\d+)(-?)([CP])(-?)(\d+)"); if (match.Success) { definition.AddField(EFIXField.PutOrCall, match.Groups[3].Value == "C" ? FIXPutOrCall.Call : FIXPutOrCall.Put); definition.AddField(EFIXField.StrikePrice, double.Parse(match.Groups[5].Value)); } break; default: securityType2 = FIXSecurityType.NoSecurityType; break; } definition.AddField(EFIXField.SecurityType, securityType2); } { double x = inst.minPriceFluctuation; int i = 0; for (; x - (int)x != 0; ++i) { x = x * 10; } definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); } definition.AddField(EFIXField.Symbol, inst.InstrumentID); definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.TickSize, inst.minPriceFluctuation); definition.AddField(EFIXField.SecurityDesc, inst.VarietyName); definition.AddField(EFIXField.Factor, inst.contractMultiplier); try { definition.AddField(EFIXField.MaturityDate, DateTime.ParseExact(inst.instrumentMaturity, "yyyy.MM.dd", CultureInfo.InvariantCulture)); } catch (Exception ex) { tdlog.Warn("合约:{0},字段内容:{1},{2}", inst.InstrumentID, inst.instrumentMaturity, ex.Message); } //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } #endregion #region 组合 foreach (DFITCAbiInstrumentRtnField inst in list1) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count + list1.Count, }; string securityType2 = FIXSecurityType.MultiLegInstrument; definition.AddField(EFIXField.SecurityType, securityType2); definition.AddField(EFIXField.Symbol, inst.InstrumentID);// definition.AddField(EFIXField.SecurityExchange, inst.ExchangeID); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.instrumentName); if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } #endregion } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { if (!this.IsConnected) { this.EmitError(1, 1, "Instrument provider not connected."); return; } string[] markets = marketFilters.Split(','); //是否包含交易市场 if (request.ContainsField(0xcf) && markets.Contains(request.SecurityExchange)) { DZHSymbolReader reader = new DZHSymbolReader(dzhDataPath); string[] securityTypes = securityTypeFilters.Split(','); List <DZHSymbol> symbolList = reader.GetSymbols(request.SecurityExchange); reader.Dispose();//显式释放资源 if (symbolList != null) { List <DZHSymbol> symbols = new List <DZHSymbol>(); foreach (DZHSymbol symbol in symbolList) { if (securityTypes.Contains(symbol.SecurityType.ToString())) { symbols.Add(symbol); } } foreach (DZHSymbol symbol in symbols) { FIXSecurityDefinition definition = new FIXSecurityDefinition(request.SecurityReqID, request.SecurityReqID, 4); definition.SecurityExchange = symbol.Market; definition.SecurityID = symbol.Code; definition.SecurityIDSource = "8";// 8=Exchange Symbol definition.Symbol = symbol.ToString(); switch (symbol.SecurityType) { case DZHSymbol.SecurityTypes.Index: definition.SecurityType = "IDX"; break; case DZHSymbol.SecurityTypes.Stock: definition.SecurityType = "CS"; break; default: definition.SecurityType = symbol.SecurityType.ToString().Substring(0, 3); break; } definition.SecuritySubType = symbol.StockType.ToString(); definition.SecurityDesc = symbol.Name; definition.TotNoRelatedSym = symbols.Count; if (this.SecurityDefinition != null) { this.SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (this) { string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List<StockInfoEx> list = new List<StockInfoEx>(); foreach (StockInfoEx inst in _dictInstruments.Values) { int flag = 0; if (null == symbol) { ++flag; } else if (inst.stockinfo.szCode.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (inst.market.ToUpper().StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (FIXSecurityType.Future == securityType) { ++flag; } } if (3 == flag) { list.Add(inst); } } #endregion list.Sort(SortStockInfoEx); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (StockInfoEx inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; definition.AddField(EFIXField.SecurityType, FIXSecurityType.Future); definition.AddField(EFIXField.Symbol, inst.stockinfo.szCode); definition.AddField(EFIXField.SecurityExchange, inst.market); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.stockinfo.szName); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }
public void SendSecurityDefinitionRequest(FIXSecurityDefinitionRequest request) { lock (_dictDepthMarketData) { string symbol = request.ContainsField(EFIXField.Symbol) ? request.Symbol : null; string securityType = request.ContainsField(EFIXField.SecurityType) ? request.SecurityType : null; string securityExchange = request.ContainsField(EFIXField.SecurityExchange) ? request.SecurityExchange : null; #region 过滤 List<StructRcvReportEx> list = new List<StructRcvReportEx>(); foreach (StructRcvReport inst in _dictDepthMarketData.Values) { StructRcvReportEx ex = new StructRcvReportEx(inst); int flag = 0; if (null == symbol) { ++flag; } else if (ex.newSymbol.ToUpper().StartsWith(symbol.ToUpper())) { ++flag; } if (null == securityExchange) { ++flag; } else if (ex.yahooExchange.StartsWith(securityExchange.ToUpper())) { ++flag; } if (null == securityType) { ++flag; } else { if (securityType == ex.securityType) { ++flag; } } if (3 == flag) { list.Add(ex); } } #endregion list.Sort(SortCThostFtdcInstrumentField); //如果查出的数据为0,应当想法立即返回 if (0 == list.Count) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = 1//有个除0错误的问题 }; if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } foreach (StructRcvReportEx inst in list) { FIXSecurityDefinition definition = new FIXSecurityDefinition { SecurityReqID = request.SecurityReqID, //SecurityResponseID = request.SecurityReqID, SecurityResponseType = request.SecurityRequestType, TotNoRelatedSym = list.Count }; { definition.AddField(EFIXField.SecurityType, inst.securityType); } { //double x = inst.PriceTick; //if (x > 0.0001) //{ // int i = 0; // for (; x - (int)x != 0; ++i) // { // x = x * 10; // } // definition.AddField(EFIXField.PriceDisplay, string.Format("F{0}", i)); // definition.AddField(EFIXField.TickSize, inst.PriceTick); //} } definition.AddField(EFIXField.Symbol, GetYahooSymbol(inst.newSymbol, inst.yahooExchange)); definition.AddField(EFIXField.SecurityExchange, inst.yahooExchange); definition.AddField(EFIXField.Currency, "CNY");//Currency.CNY definition.AddField(EFIXField.SecurityDesc, inst.RcvReport.StockName); FIXSecurityAltIDGroup group = new FIXSecurityAltIDGroup(); group.SecurityAltID = inst.RcvReport.StockCode; group.SecurityAltExchange = inst.RcvReport.MarketType; group.SecurityAltIDSource = this.Name; definition.AddGroup(group); //还得补全内容 if (SecurityDefinition != null) { SecurityDefinition(this, new SecurityDefinitionEventArgs(definition)); } } } }