//设置缓存数据对象
        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);
        }
Esempio n. 2
0
        //设置正数据对象-修正为同时间频率数据
        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);
        }
Esempio n. 3
0
        /// <summary>转换json行情数据为行情对象集
        /// </summary>
        /// <param name="jsonRes">json行情数据对象</param>
        /// <returns></returns>
        protected internal List <Data_Quote> TransTo_Data_Quotes(JObject jsonRes, typeTimeFrequency quoteTime, StockInfo pStockInfo = null)
        {
            //数据检查
            if (jsonRes == null)
            {
                return(null);
            }
            if (jsonRes["result"].ToString() == "False")
            {
                return(null);
            }

            //循环解析文件json数据
            List <Data_Quote> lstDataQuote = new List <Data_Quote>();
            JArray            jsonDatas    = (JArray)jsonRes["datas"];

            if (jsonDatas != null)
            {
                //循环生成数据对象
                string platSrc = jsonRes["datasPlat"] + "";
                foreach (var jsonData in jsonDatas)
                {
                    Data_Quote pDataQuote = null;
                    switch (quoteTime)
                    {
                    case typeTimeFrequency.none:
                        break;

                    case typeTimeFrequency.real:
                        pDataQuote = new Data_Quote_Realtime_5Stalls(pStockInfo);
                        break;

                    default:
                        pDataQuote = new Data_Quote(pStockInfo);
                        break;
                    }
                    if (pDataQuote == null)
                    {
                        continue;
                    }

                    //转换为行情数据对象
                    //if (platSrc == typeQuotePlat.JQDataAPI_zxc.ToString())
                    //{
                    //    pDataQuote = JsonConvert.DeserializeObject<Data_Quote_Info>(JsonConvert.SerializeObject(jsonData));
                    //    pDataQuote.QuoteTimeType = quoteTime;
                    //    lstDataQuote.Add(pDataQuote);
                    //}
                    if (pDataQuote.FromJson(jsonData))
                    {
                        pDataQuote.QuoteTimeType = quoteTime;
                        pDataQuote.Check_DateTime();
                        lstDataQuote.Add(pDataQuote);
                    }
                }
            }
            return(lstDataQuote);
        }
Esempio n. 4
0
 //数据检查实现(具化数据对象及缓存)-使用基类
 public override bool CheckData(DateTime dtTime, T data, IDataCache <T> dataCache = null)
 {
     if (dataCache != null)
     {
         this._DataCache = dataCache;
     }
     _data = data;
     return(true);
 }
Esempio n. 5
0
        //数据监测实现(具化数据对象及缓存)-观察者模式
        public virtual bool Calculate(DateTime dtTime, Data_Quote data)
        {
            bool bResult = true;

            foreach (KeyValuePair <typeIndex, QuantifyIndex> quoteIndex in _QuantifyIndexs)
            {
                bResult = bResult && (quoteIndex.Value.Calculate(dtTime, data) != double.NaN);
            }
            return(bResult);
        }
        //设置缓存数据对象
        public virtual bool SetDataCache(Data_Quote pData)
        {
            bool   bInited = false;
            string tag     = _getTag(pData);

            _dictQuotes.TryGetValue(tag, out bInited);
            if (!bInited)
            {
                this.InitDataCache(pData);
            }
            return(this.SetData(pData, pData.QuoteTimeType));
        }
Esempio n. 7
0
        //数据监测实现(具化数据对象及缓存)-观察者模式
        public override bool CheckDatas <T>(DateTime dtTime, T data, IDataCache <T> dataCache)
        {
            bool bResult = true;

            foreach (KeyValuePair <string, IDataCheck> check in _DataChecks)
            {
                DataCheck_Quote <Data_Quote> dataCheck = (DataCheck_Quote <Data_Quote>)check.Value;
                if (dataCheck == null)
                {
                    continue;
                }
                if (!dataCheck.IsValid)
                {
                    continue;
                }

                Data_Quote pQuote = (Data_Quote)zxcReflectionHelper.ConvertToObject(data, typeof(Data_Quote));
                if (pQuote != null)
                {
                    bResult = dataCheck.CheckData(dtTime, pQuote, (IDataCache <Data_Quote>)dataCache) && bResult;
                }
            }
            return(bResult);
        }
Esempio n. 8
0
 /// <summary>计算指定时间指标
 /// </summary>
 /// <param name="dtNow"></param>
 /// <param name="data">当前时间数据</param>
 /// <returns></returns>
 public virtual double Calculate(DateTime dtNow, Data_Quote data = null, bool isLastData = false)
 {
     return(double.NaN);
 }
        //提取对象标识名
        protected internal virtual string _getTag(Data_Quote pData)
        {
            StockInfo pStockInfo = pData.GetStockInfo();

            return(pStockInfo.StockExchange.ToString() + "_" + pStockInfo.StockID_Tag);
        }
Esempio n. 10
0
        //初始规则信息集合-Cache-弃用
        private bool InitDataChecks_Cache(IData_Factors pFactors, IData_Factor pFactor, Data_Quote data)
        {
            //数据缓存集检查
            IDataCaches dataCaches = _managerCaches.GetDataCaches(pFactors, pFactor);

            if (dataCaches == null)
            {
                return(false);
            }

            //初始检查集
            bool bResult = this.InitDataChecks_CheckAll(dataCaches);

            return(bResult);
        }
Esempio n. 11
0
        //统一初始数据缓存相关
        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);
        }
Esempio n. 12
0
        /// <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);
        }