public bool IsNormalOpenCloseTime(string instrumentid) { Instrument instr = this[instrumentid]; if (instr == null) { return(true); } if (instr.Market == EnumMarket.期货) { Future future = instr as Future; if (future == null) { return(true); } FutureProduct product = GetFutureProduct(future.ProductID); if (product == null) { return(true); } if (product.AllSlice != null && product.AllSlice.Count > 0) { return(false); } } return(true); }
internal void AddProduct(FutureProduct product) { if (product == null) { return; } if (_allProducts.ContainsKey(product.ProductID)) { return; } _allProducts.Add(product.ProductID, product); }
private static List <TimeSlice> GetTradingTime(InstrumentManager instmgr, string instid, DateTime tradingday) { List <TimeSlice> tradingtime = instmgr.GetTradingTime(tradingday, instid); Instrument instr = instmgr[instid]; string productid = Regex.Replace(instid, @"\d", ""); if (instr != null && instr.Market == EnumMarket.期货期权) { productid = ((Option)instr).ProductID; } FutureProduct product = instmgr.GetFutureProduct(productid); return(tradingtime); }
public TimeSlice GetLivingTime(string futureid) { Future future = this[futureid]; if (future == null) { return(null); } FutureProduct product = GetProductById(future.ProductID); if (product == null) { return(null); } if (product.AllSlice != null && product.AllSlice.Count > 0) { TimeSlice tslice = new TimeSlice(); tslice.BeginTime = product.AllSlice[0].BeginTime; tslice.EndTime = product.AllSlice[product.AllSlice.Count - 1].EndTime; return(tslice); } Exchange exchange = GetExchange(future.ExchangeID); if (exchange == null) { return(null); } if (exchange.AllSlice != null && exchange.AllSlice.Count > 0) { TimeSlice tslice = new TimeSlice(); tslice.BeginTime = exchange.AllSlice[0].BeginTime; tslice.EndTime = exchange.AllSlice[exchange.AllSlice.Count - 1].EndTime; return(tslice); } return(null); }
internal static void Set(XmlDocument doc, XmlElement root, FutureProduct product, FutureManager mgr) { XmlAttribute attr = doc.CreateAttribute(IdAttr); attr.Value = product.ProductID; root.Attributes.Append(attr); attr = doc.CreateAttribute(NameAttr); attr.Value = product.ProductName; root.Attributes.Append(attr); if (product.AllSlice != null && product.AllSlice.Count > 0) { StringBuilder builder = new StringBuilder(); foreach (TimeSlice slice in product.AllSlice) { builder.Append(slice.BeginTime.ToString()).Append(",") .Append(slice.EndTime.ToString()).Append(","); } builder.Remove(builder.Length - 1, 1); attr = doc.CreateAttribute(TradingTimeAttr); attr.Value = builder.ToString(); root.Attributes.Append(attr); } List <Future> futurelist = mgr.GetFutures(product.ExchangeID, product.ProductID); foreach (Future future in futurelist) { XmlElement subTagNode = doc.CreateElement(FutureTag); root.AppendChild(subTagNode); FutureXml.Set(doc, subTagNode, future); } }
public bool LoadConfig(string strFile) { try { XmlDocument doc = new XmlDocument(); doc.Load(strFile); #region 交易所 XmlElement exroot = doc.DocumentElement.GetElementsByTagName(ExListTag)[0] as XmlElement; if (exroot == null) { throw new Exception("文件格式不对"); } TimeSpan tsvalue; foreach (XmlNode node in exroot) { #region XmlElement exElem = node as XmlElement; if (exElem == null) { continue; } Exchange exchange = new Exchange(); exchange.ExchangeID = exElem.GetAttribute(IdAttr).Trim(); exchange.ExchangeName = exElem.GetAttribute(NameAttr).Trim(); if (exchange.ExchangeID.Length == 0) { continue; } XmlText txtNode = null; DateTime dtime = default(DateTime); foreach (XmlNode subNode in exElem.ChildNodes) { #region XmlElement subTagNode = subNode as XmlElement; if (subTagNode == null) { continue; } switch (subTagNode.Name) { case SliceTag: txtNode = subTagNode.FirstChild as XmlText; if (txtNode == null || txtNode.Value.Trim() == "") { throw new Exception("配置文件格式不对"); } string[] strlist = txtNode.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int icount = strlist.Length / 2; for (int i = 0; i < icount; ++i) { TimeSlice slice = new TimeSlice(); if (!TimeSpan.TryParse(strlist[i * 2], out tsvalue)) { exchange.AllSlice.Clear(); throw new Exception("配置文件格式不对"); } slice.BeginTime = tsvalue; if (!TimeSpan.TryParse(strlist[i * 2 + 1], out tsvalue)) { exchange.AllSlice.Clear(); throw new Exception("配置文件格式不对"); } slice.EndTime = tsvalue; exchange.AllSlice.Add(slice); } break; case OpenTimeTag: txtNode = subTagNode.FirstChild as XmlText; if (txtNode == null || txtNode.Value.Trim() == "") { throw new Exception("配置文件格式不对"); } if (!DateTime.TryParse(txtNode.Value, out dtime)) { throw new Exception("配置文件格式不对"); } exchange.OpenTime = dtime; break; case CloseTimeTag: txtNode = subTagNode.FirstChild as XmlText; if (txtNode == null || txtNode.Value.Trim() == "") { throw new Exception("配置文件格式不对"); } if (!DateTime.TryParse(txtNode.Value, out dtime)) { throw new Exception("配置文件格式不对"); } exchange.CloseTime = dtime; break; } #endregion } _exlist.Add(exchange.ExchangeID, exchange); #endregion } #endregion #region 品种 XmlElement productroot = doc.DocumentElement.GetElementsByTagName(PrdListTag)[0] as XmlElement; if (productroot == null) { throw new Exception("文件格式不对"); } foreach (XmlNode node in productroot) { XmlElement productElem = node as XmlElement; if (productElem == null) { continue; } FutureProduct product = new FutureProduct(); product.ProductID = productElem.GetAttribute("id").Trim(); product.ProductName = productElem.GetAttribute("name").Trim(); product.ExchangeID = productElem.GetAttribute("exchange").Trim(); if (productElem.HasAttribute(TradingTimeAttr)) { #region tradingtime string strtradingtime = productElem.GetAttribute(TradingTimeAttr); string[] strlist = strtradingtime.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int icount = strlist.Length / 2; for (int i = 0; i < icount; ++i) { TimeSlice slice = new TimeSlice(); if (!TimeSpan.TryParse(strlist[i * 2], out tsvalue)) { product.AllSlice.Clear(); throw new Exception("配置文件future.xml格式不对, Product/tradingtime解析出错"); } slice.BeginTime = tsvalue; if (!TimeSpan.TryParse(strlist[i * 2 + 1], out tsvalue)) { product.AllSlice.Clear(); throw new Exception("配置文件future.xml格式不对, Product/tradingtime解析出错"); } slice.EndTime = tsvalue; product.AllSlice.Add(slice); } #endregion } if (product.ProductID.Length != 0) { _productlist.Add(product.ProductID, product); } } #endregion #region 合约 XmlElement futureroot = doc.DocumentElement.GetElementsByTagName(FutureListTag)[0] as XmlElement; if (futureroot == null) { throw new Exception("文件格式不对"); } foreach (XmlNode node in futureroot) { XmlElement futureElem = node as XmlElement; if (futureElem == null) { continue; } Future future = new Future(); future.ID = futureElem.GetAttribute("id").Trim(); future.Name = futureElem.GetAttribute("name").Trim(); future.ProductID = futureElem.GetAttribute("pid").Trim(); if (future.ID.Length != 0) { if (future.ProductID == "default") { _defaultfuturelist.Add(future); } else { _futurelist.Add(future); } } } #endregion return(true); } catch (XmlException xmlex) { ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); logger.Error("加载配置文件 " + strFile + " 失败", xmlex); } catch (Exception e) { ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); logger.Error("加载配置文件 " + strFile + " 失败", e); } _exlist.Clear(); return(false); }
internal static void Get( XmlElement root, FutureProduct product, FutureManager mgr, List <string> futurelist, bool blive) { product.ProductID = root.GetAttribute(IdAttr); product.ProductName = root.GetAttribute(NameAttr); if (root.HasAttribute(TradingTimeAttr)) { #region tradingtime string strtradingtime = root.GetAttribute(TradingTimeAttr); string[] strlist = strtradingtime.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int icount = strlist.Length / 2; TimeSpan tsvalue; for (int i = 0; i < icount; ++i) { TimeSlice slice = new TimeSlice(); if (!TimeSpan.TryParse(strlist[i * 2], out tsvalue)) { product.AllSlice.Clear(); throw new Exception("配置文件future.xml格式不对, Product/tradingtime解析出错"); } slice.BeginTime = tsvalue; if (!TimeSpan.TryParse(strlist[i * 2 + 1], out tsvalue)) { product.AllSlice.Clear(); throw new Exception("配置文件future.xml格式不对, Product/tradingtime解析出错"); } slice.EndTime = tsvalue; product.AllSlice.Add(slice); } #endregion } Dictionary <string, Future> normalmap = new Dictionary <string, Future>(); Dictionary <string, Future> refmap = new Dictionary <string, Future>(); Dictionary <string, Future> idxmap = new Dictionary <string, Future>(); foreach (XmlNode subNode in root.ChildNodes) { #region XmlElement subTagNode = subNode as XmlElement; if (subTagNode == null) { continue; } if (subTagNode.Name != FutureTag) { continue; } Future future; FutureXml.Get(subTagNode, out future, blive); if (future.ID != "") { future.ExchangeID = product.ExchangeID; future.ProductID = product.ProductID; if (future.FutureType == EnumFutureType.Index) { if (!idxmap.ContainsKey(future.ID)) { idxmap.Add(future.ID, future); } else { throw new Exception("Future.xml出错,重复的合约ID: " + future.ID); } } else if (future.FutureType == EnumFutureType.Reference) { if (!refmap.ContainsKey(future.ID)) { refmap.Add(future.ID, future); } else { throw new Exception("Future.xml出错,重复的合约ID: " + future.ID); } } else { if (!normalmap.ContainsKey(future.ID)) { normalmap.Add(future.ID, future); } else { throw new Exception("Future.xml出错,重复的合约ID: " + future.ID); } } } #endregion } foreach (string futureid in normalmap.Keys) { if (futurelist == null || futurelist.Count == 0 || futurelist.Contains(futureid)) { mgr.AddFuture(normalmap[futureid]); } } foreach (string futureid in refmap.Keys) { Future future = refmap[futureid]; string refid = mgr.GetRealFuture(future.ID); if (refid != "" && normalmap.ContainsKey(refid)) { future.RealFuture = normalmap[refid]; } if (futurelist == null || futurelist.Count == 0 || futurelist.Contains(futureid)) { mgr.AddFuture(future); mgr.AddFuture(future.RealFuture); } } foreach (string futureid in idxmap.Keys) { if (futurelist == null || futurelist.Count == 0 || futurelist.Contains(futureid)) { Future future = idxmap[futureid]; future.RealFuture = refmap[future.ProductID + "9999"].RealFuture; mgr.AddFuture(future); mgr.AddFuture(future.RealFuture); foreach (string normalid in normalmap.Keys) { mgr.AddFuture(normalmap[normalid]); } } } BuildRef(mgr, product.ExchangeID, product.ProductID); }
internal static void Get(XmlElement root, FutureProduct product, FutureManager mgr) { product.ProductID = root.GetAttribute(IdAttr); product.ProductName = root.GetAttribute(NameAttr); if (root.HasAttribute(TradingTimeAttr)) { #region tradingtime string strtradingtime = root.GetAttribute(TradingTimeAttr); string[] strlist = strtradingtime.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int icount = strlist.Length / 2; TimeSpan tsvalue; for (int i = 0; i < icount; ++i) { TimeSlice slice = new TimeSlice(); if (!TimeSpan.TryParse(strlist[i * 2], out tsvalue)) { product.AllSlice.Clear(); throw new Exception("配置文件future.xml格式不对, Product/tradingtime解析出错"); } slice.BeginTime = tsvalue; if (!TimeSpan.TryParse(strlist[i * 2 + 1], out tsvalue)) { product.AllSlice.Clear(); throw new Exception("配置文件future.xml格式不对, Product/tradingtime解析出错"); } slice.EndTime = tsvalue; product.AllSlice.Add(slice); } #endregion } foreach (XmlNode subNode in root.ChildNodes) { XmlElement subTagNode = subNode as XmlElement; if (subTagNode == null) { continue; } if (subTagNode.Name != FutureTag) { continue; } Future future; FutureXml.Get(subTagNode, out future, false); if (future.ID != "") { future.ExchangeID = product.ExchangeID; future.ProductID = product.ProductID; mgr.AddFuture(future); } } BuildRef(mgr, product.ExchangeID, product.ProductID); }
/// <summary> /// 解析内容 /// </summary> /// <param name="root"></param> /// <param name="exchange"></param> /// <param name="mgr"></param> internal static void Get(XmlElement root, Exchange exchange, FutureManager mgr) { exchange.ExchangeID = root.GetAttribute(IdAttr); exchange.ExchangeName = root.GetAttribute(NameAttr); XmlText txtNode = null; DateTime dtime = default(DateTime); TimeSpan tsvalue; foreach (XmlNode subNode in root.ChildNodes) { XmlElement subTagNode = subNode as XmlElement; if (subTagNode == null) continue; switch (subTagNode.Name) { case ProductTag: FutureProduct product = new FutureProduct(); product.ExchangeID = exchange.ExchangeID; FutureProductXml.Get(subTagNode, product, mgr); if (product.ProductID != "") mgr.AddProduct(product); break; case SliceTag: txtNode = subTagNode.FirstChild as XmlText; if (txtNode == null || txtNode.Value.Trim() == "") throw new Exception("配置文件格式不对"); string[] strlist = txtNode.Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); int icount = strlist.Length / 2; for (int i = 0; i < icount; ++i) { TimeSlice slice = new TimeSlice(); if (!TimeSpan.TryParse(strlist[i * 2], out tsvalue)) { exchange.AllSlice.Clear(); throw new Exception("配置文件格式不对"); } slice.BeginTime = tsvalue; if (!TimeSpan.TryParse(strlist[i * 2 + 1], out tsvalue)) { exchange.AllSlice.Clear(); throw new Exception("配置文件格式不对"); } slice.EndTime = tsvalue; exchange.AllSlice.Add(slice); } break; case OpenTimeTag: txtNode = subTagNode.FirstChild as XmlText; if (txtNode == null || txtNode.Value.Trim() == "") throw new Exception("配置文件格式不对"); if (!DateTime.TryParse(txtNode.Value, out dtime)) throw new Exception("配置文件格式不对"); exchange.OpenTime = dtime; break; case CloseTimeTag: txtNode = subTagNode.FirstChild as XmlText; if (txtNode == null || txtNode.Value.Trim() == "") throw new Exception("配置文件格式不对"); if (!DateTime.TryParse(txtNode.Value, out dtime)) throw new Exception("配置文件格式不对"); exchange.CloseTime = dtime; break; } } }
public TimeSlice GetLivingTime(DateTime tradingday, string instrumentid) { Instrument instr = this[instrumentid]; if (instr != null && _tfMgr != null) { string productid = GetProduct(instrumentid); return(_tfMgr.GetLivingTime(tradingday, instr.Market, instr.ExchangeID, productid)); } if (instr == null) { //期货没有后缀 var prodct = GetProduct(instrumentid); if (prodct == "" || prodct[0] == '.') { return(null); } FutureProduct product = GetFutureProduct(prodct); if (product == null) { return(null); } if (product.AllSlice != null && product.AllSlice.Count > 0) { TimeSlice tslice = new TimeSlice { BeginTime = product.AllSlice[0].BeginTime, EndTime = product.AllSlice[product.AllSlice.Count - 1].EndTime }; return(tslice); } Exchange exchange = GetExchange(product.ExchangeID); if (exchange == null) { return(null); } if (exchange.AllSlice != null && exchange.AllSlice.Count > 0) { TimeSlice tslice = new TimeSlice { BeginTime = exchange.AllSlice[0].BeginTime, EndTime = exchange.AllSlice[exchange.AllSlice.Count - 1].EndTime }; return(tslice); } } else { if (instr.Market == EnumMarket.期货) { Future future = instr as Future; if (future == null) { return(null); } FutureProduct product = GetFutureProduct(future.ProductID); if (product == null) { return(null); } if (product.AllSlice != null && product.AllSlice.Count > 0) { TimeSlice tslice = new TimeSlice(); tslice.BeginTime = product.AllSlice[0].BeginTime; tslice.EndTime = product.AllSlice[product.AllSlice.Count - 1].EndTime; return(tslice); } } Exchange exchange = GetExchange(instr.ExchangeID); if (exchange == null) { return(null); } if (exchange.AllSlice != null && exchange.AllSlice.Count > 0) { TimeSlice tslice = new TimeSlice(); tslice.BeginTime = exchange.AllSlice[0].BeginTime; tslice.EndTime = exchange.AllSlice[exchange.AllSlice.Count - 1].EndTime; return(tslice); } } return(null); }
/// <summary> /// 获取品种的交易时间 /// </summary> /// <param name="instrumentid">品种</param> /// <returns></returns> public List <TimeSlice> GetTradingTime(DateTime tradingday, string instrumentid) { #region Instrument instr = this[instrumentid]; if (instr != null && _tfMgr != null) { string productid = GetProduct(instrumentid); if (instr.Market == EnumMarket.期货期权) { productid = ((Option)instr).ProductID; } return(_tfMgr.GetTradingFrame(tradingday, instr.Market, instr.ExchangeID, productid)); } if (instr == null) { //期货没有后缀 var prodct = GetProduct(instrumentid); if (prodct == "" || prodct[0] == '.') { return(null); } FutureProduct product = GetFutureProduct(prodct); if (product == null) { return(null); } if (product.AllSlice != null && product.AllSlice.Count > 0) { return(product.AllSlice); } Exchange exchange = GetExchange(product.ExchangeID); if (exchange == null) { return(null); } return(exchange.AllSlice); } else { if (instr.Market == EnumMarket.期货) { Future future = instr as Future; if (future == null) { return(null); } FutureProduct product = GetFutureProduct(future.ProductID); if (product == null) { return(null); } if (product.AllSlice != null && product.AllSlice.Count > 0) { return(product.AllSlice); } } Exchange exchange = GetExchange(instr.ExchangeID); if (exchange == null) { return(null); } return(exchange.AllSlice); } return(null); #endregion }