//设置缓存数据对象 public virtual bool SetData(Data_Quote pData, typeTimeFrequency timeFrequency) { StockInfo stockInfo = pData.GetStockInfo(); if (stockInfo == null) { return(false); } //默认只设置最底级数据, bool bResult = true; string exType = stockInfo.StockExchange.ToString(); //Data_Quote dataCheck = this.SetData_ValueCheck(stockInfo, pData, timeFrequency); if (pData != null) { bResult = bResult && _managerCaches.SetData <Data_Quote>(exType, stockInfo.StockID_Tag, "", pData.DateTime, pData, timeFrequency); } //foreach (var item in _setsDataCache) //{ // Data_Quote dataCheck = this.SetDataCache_ValueCheck(pData, item.Key); // if (dataCheck != null) // { // bResult = bResult && _managerCaches.SetData<Data_Quote>(exType, stockInfo.StockID_Tag, "", dataCheck.DateTime, dataCheck, item.Key); // } //} return(bResult); }
//设置正数据对象-修正为同时间频率数据 public virtual bool SetData(CacheInfo <Data_Quote> pCacheInfo, typeTimeFrequency timeFrequency, typeTimeFrequency timeFrequency2) { Data_Quote pData = pCacheInfo.Data; if (pData == null) { return(false); } StockInfo pStockInfo = pData.GetStockInfo(); if (pStockInfo == null) { return(false); } //获取当前时间频率数据 DateTime dtEnd = zxcTimeHelper.CheckTime(pData.DateTime, typeTimeFrequency.m1, true); Data_Quote pDataNew = QuoteQuery._Query.Query(pStockInfo, pData.DateTime, timeFrequency, null); if (pDataNew == null) { return(false); } bool bResult = this.SetData(pDataNew, timeFrequency); return(bResult); //非时间频率数据,重新修正 if (pData.QuoteTimeType != timeFrequency) { string exType = pStockInfo.StockExchange.ToString(); IData_Factors pFactors = _managerCaches._GetFactors(exType); if (pFactors != null) { IData_Factor pFactor = pFactors.GetData_Factor(pStockInfo.StockID_Tag); DataCache <Data_Quote> pDataCache = (DataCache <Data_Quote>)_managerCaches.GetDataCache <Data_Quote>(pFactors, pFactor, "", timeFrequency); //查询最后有效步长数据总数 int nCount = pDataCache.DataCaches.Values.Count(e => e.Data.IsDel == true); //获取最数据 List <Data_Quote> lstQuotes = QuoteQuery._Query.Query(pStockInfo.StockID_Tag, pDataNew.DateTime, nCount, timeFrequency, true); if (lstQuotes != null) { foreach (var item in lstQuotes) { int nSum = pDataCache.DataCaches.Values.Count(e => e.DateTime == item.DateTime && e.Data.IsDel != true); if (nSum == 0) { item.SetStockInfo(pStockInfo); bResult = bResult && this.SetData(item, timeFrequency); } } } } } return(bResult); }
//提取对象标识名 protected internal virtual string _getTag(Data_Quote pData) { StockInfo pStockInfo = pData.GetStockInfo(); return(pStockInfo.StockExchange.ToString() + "_" + pStockInfo.StockID_Tag); }
//统一初始数据缓存相关 public virtual bool InitDataCache(Data_Quote pData) { if (pData == null) { return(false); } StockInfo stockInfo = pData.GetStockInfo(); if (stockInfo == null) { return(false); } string exType = stockInfo.StockExchange.ToString(); bool bExist = true, bResult = true; IData_Factors pFactors = _managerCaches._GetFactors(exType); if (pFactors == null) { //提取信息 pFactors = new Data_Factors(exType, exType, "", ""); pFactors.DateTime = pData.DateTime; bExist = false; } IData_Factor pFactor = pFactors.GetData_Factor(stockInfo.StockID_Tag); if (bExist == false || pFactor == null) { //提取信息 pFactor = new Data_Factor(stockInfo.StockID_Tag, stockInfo.StockID_Tag, stockInfo.StockName, ""); pFactor.DateTime = pFactors.DateTime; //初始数据所有缓存对象 if (this._managerCaches.DataCaches_Manages.Count < 1) { this._managerCaches.Init(pFactors.DateTime); } foreach (var item in _setsDataCache) { //提取数据缓存对象、及检查对象集 IDataCache <Data_Quote> poDataCache = _managerCaches.GetDataCache <Data_Quote>(pFactors, pFactor, "", item.Key, true, item.Value); //IDataCache poDataCache = null; //if (item.Key == typeTimeFrequency.real) // poDataCache = _managerCaches.GetDataCache<Data_Quote>(pFactors, pFactor, "", item.Key, true, item.Value); //else // poDataCache = _managerCaches.GetDataCache<Data_Quote>(pFactors, pFactor, "", item.Key, true, item.Value); //_managerCaches.InitDataCache<Data_Quote_Swap>(pFactors, pFactor, "", item.Key, item.Value); } //初始规则信息集合-Caches //bResult = this.InitDataChecks_Caches(pFactors, pFactor); //初始规则信息集合-Cache //bResult = bResult && this.InitDataChecks_Cache(pFactors, pFactor, data); _dictQuotes[_getTag(pData)] = true; return(bResult); } return(false); }
/// <summary>查询历史行情 (含自算实时-当未过时间标识时) /// </summary> /// <param name="pStockInfo">标的信息</param> /// <param name="startTime">开始时间</param> /// <param name="endTime">结束时间</param> /// <param name="quoteTime">时间类型</param> /// <param name="quoteBase">基础行情数据</param> /// <returns></returns> protected internal Data_Quote Query(StockInfo pStockInfo, DateTime endTime, typeTimeFrequency quoteTime = typeTimeFrequency.m5, Data_Quote quoteBase = null, bool autoStatics = false) { if (pStockInfo == null) { return(null); } //校正时间 Data_Quote pQuote = null; DateTime dtEnd = zxcTimeHelper.CheckTime(endTime, quoteTime, true); if (DateTime.Now > dtEnd) { pQuote = QuoteQuery._Query.Query(pStockInfo.StockID_Tag, dtEnd, 1, quoteTime, true).FirstOrDefault(); if (pQuote != null && pQuote.DateTime == dtEnd) { if (pQuote.GetStockInfo() == null) { pQuote.SetStockInfo(pStockInfo); } //修正开盘值 if (pQuote.Price_Per == 0 && double.IsInfinity(pQuote.Value_RF)) { Data_Quote pQuote_Day = QuoteQuery._Query.Query(pStockInfo.StockID_Tag, dtEnd, 1, typeTimeFrequency.day, true).FirstOrDefault(); if (pQuote_Day != null) { pQuote.Init_Price_Base(pQuote_Day.Price_Per); } } return(pQuote); } } if (!autoStatics) { return(null); } //获取最数据,自行计算 if ((int)quoteTime < 4) { return(null); } int nCount = (int)quoteTime.Get_Value() / 60; List <Data_Quote> lstQuotes = QuoteQuery._Query.Query(pStockInfo.StockID_Tag, dtEnd, nCount, typeTimeFrequency.m1, true); //统计最大最小 DataStatistics pStatistics = new DataStatistics(); pStatistics.Init(lstQuotes[0].Price_Close, lstQuotes[0].DateTime); foreach (var item in lstQuotes) { pStatistics.Statistics(item.Price_High, item.DateTime); pStatistics.Statistics(item.Price_Low, item.DateTime); pStatistics.Statistics(item.Price_Close, item.DateTime); } if (quoteBase != null) { pStatistics.Statistics(quoteBase.Price_High, quoteBase.DateTime); pStatistics.Statistics(quoteBase.Price_Low, quoteBase.DateTime); pStatistics.Statistics(quoteBase.Price_Close, quoteBase.DateTime); } //实例新数据 Data_Quote pQuote_New = new Data_Quote(pStockInfo) { Price_Close = pStatistics.Value_Original, Price_High = pStatistics.Max_Original, Price_Low = pStatistics.Min_Original, QuotePlat = typeQuotePlat.none, QuoteTimeType = quoteTime, DateTime = dtEnd, IsDel = true }; return(pQuote_New); }