示例#1
0
 public bool IsSame(ConfigInfo config)
 {
     return Version == config.Version
            && TickSize == config.TickSize
            && TickSizeMultiplier == config.TickSizeMultiplier
            && SettlementPriceMultiplier == config.SettlementPriceMultiplier
            && AveragePriceMultiplier == config.AveragePriceMultiplier
            && ContractMultiplier == config.ContractMultiplier
            && Time_ssf_Diff == config.Time_ssf_Diff
            && MarketDepth == config.MarketDepth
            && MarketType == config.MarketType
            && Volume_Total_Or_Increment == config.Volume_Total_Or_Increment
            && Turnover_Total_Or_Increment == config.Turnover_Total_Or_Increment;
     ;
 }
示例#2
0
        /// <summary>
        /// 将结构体的数据展开到列表中
        /// 读取出数据后立即使用展开,其它时候都不要调用
        /// 以后用户要使用数据时直接操作列表即可
        /// </summary>
        public void PrepareObjectAfterRead(ConfigInfo _Config)
        {
            if (Depth == null || Depth.IsZero)
            {
                DepthList = null;
                return;
            }

            List <DepthItem> tempList = new List <DepthItem>();

            DepthListHelper.StructToList(Depth, _Config.MarketType, tempList);
            // 不能这么写,因为还原时LastPrice还是一个很小的值
            //if (tempList.Count > 0)
            //    tempList[0].Price = LastPrice + tempList[0].Price;

            DepthList = new List <DepthItem>();
            DepthListHelper.PriceAddInOneList(tempList, DepthList);
        }
示例#3
0
        /// <summary>
        /// 将列表中的数据平铺到结构体中
        /// 只在保存到文件时操作,其它时候都不要调用
        /// 以后用户要使用数据时直接操作列表即可
        /// </summary>
        public void PrepareObjectBeforeWrite(ConfigInfo _Config)
        {
            if (DepthList == null || DepthList.Count == 0)
            {
                Depth = null;
                return;
            }

            List <DepthItem> tempList = new List <DepthItem>();

            DepthListHelper.PriceMinusInOneList(DepthList, tempList);


            // 还是使用新的,因为不知道以前是否已经有数据,导致混淆
            Depth = new DepthTick();
            //if(tempList.Count>0)
            //    tempList[0].Price = LastPrice - tempList[0].Price;
            DepthListHelper.ListToStruct(tempList, _Config.MarketType, Depth);
        }
        public ConfigInfoView Int2Double(ConfigInfo config)
        {
            if (config == null)
                return null;

            var field = new ConfigInfoView();

            field.Version = config.Version;
            field.TickSize = config.TickSize;
            field.TickSizeMultiplier = config.TickSizeMultiplier;
            field.SettlementPriceMultiplier = config.SettlementPriceMultiplier;
            field.AveragePriceMultiplier = config.AveragePriceMultiplier;
            field.ContractMultiplier = config.ContractMultiplier;
            field.Time_ssf_Diff = config.Time_ssf_Diff;
            field.MarketDepth = config.MarketDepth;
            field.MarketType = config.MarketType;
            field.Volume_Total_Or_Increment = config.Volume_Total_Or_Increment;
            field.Turnover_Total_Or_Increment = config.Turnover_Total_Or_Increment;

            return field;
        }
        public ConfigInfoView Int2Double(ConfigInfo config)
        {
            if (config == null)
            {
                return(null);
            }

            var field = new ConfigInfoView();

            field.Version                     = config.Version;
            field.TickSize                    = config.TickSize;
            field.TickSizeMultiplier          = config.TickSizeMultiplier;
            field.SettlementPriceMultiplier   = config.SettlementPriceMultiplier;
            field.AveragePriceMultiplier      = config.AveragePriceMultiplier;
            field.ContractMultiplier          = config.ContractMultiplier;
            field.Time_ssf_Diff               = config.Time_ssf_Diff;
            field.MarketDepth                 = config.MarketDepth;
            field.MarketType                  = config.MarketType;
            field.Volume_Total_Or_Increment   = config.Volume_Total_Or_Increment;
            field.Turnover_Total_Or_Increment = config.Turnover_Total_Or_Increment;

            return(field);
        }
示例#6
0
        public PbTick Restore(PbTick prev, PbTick diff)
        {
            if (prev == null)
            {
                if (diff.Config == null)
                {
                    throw new Exception("快照的配置不能为空");
                }
                // 记下配置,要用到
                Config = diff.Config;
                // 是快照,直接返回
                return(diff);
            }

            var tick = new PbTick();

            #region 配置数据
            if (diff.Config == null)
            {
                // 使用上条的配置
                tick.Config = prev.Config;
            }
            else
            {
                // 新配置
                _config = diff.Config;

                // 是快照,直接返回
                return(diff);
            }
            #endregion

            Config = tick.Config;

            tick.LastPrice = prev.LastPrice + diff.LastPrice;
            tick.AskPrice1 = prev.AskPrice1 + diff.AskPrice1;

            // 前一个是完整的,后一个是做过Size和Price的调整,如何还原
            var newPrevList = new List <DepthItem>();
            var newDiffList = new List <DepthItem>();

            // 换成同长度
            DepthListHelper.ExpandTwoListsToSameLength(
                prev.DepthList, diff.DepthList,
                int.MinValue, int.MaxValue,
                newPrevList, newDiffList);

            tick.DepthList = new List <DepthItem>();
            DepthListHelper.SizeAddInTwoLists(newPrevList, newDiffList, tick.DepthList);


            #region 常用行情信息
            tick.Volume       = prev.Volume + diff.Volume;
            tick.OpenInterest = prev.OpenInterest + diff.OpenInterest;
            tick.Turnover     = prev.Turnover + diff.Turnover;
            tick.AveragePrice = prev.AveragePrice + diff.AveragePrice;
            tick.TradingDay   = prev.TradingDay + diff.TradingDay;
            tick.ActionDay    = prev.ActionDay + diff.ActionDay;

            tick.Time_HHmm      = prev.Time_HHmm + diff.Time_HHmm;
            tick.Time________ff = prev.Time________ff + diff.Time________ff;
            // 还原时间
            tick.Time_____ssf__ = prev.Time_____ssf__ + diff.Time_____ssf__ + _config.Time_ssf_Diff;
            tick.LocalTime_Msec = prev.LocalTime_Msec + diff.LocalTime_Msec;
            #endregion

            #region Bar数据
            if (prev.Bar != null || diff.Bar != null)
            {
                tick.Bar = new BarInfo();
                if (prev.Bar == null)
                {
                    prev.Bar = new BarInfo();
                }
                if (diff.Bar == null)
                {
                    diff.Bar = new BarInfo();
                }

                tick.Bar.Open    = prev.Bar.Open + diff.Bar.Open;
                tick.Bar.High    = prev.Bar.High + diff.Bar.High;
                tick.Bar.Low     = prev.Bar.Low + diff.Bar.Low;
                tick.Bar.Close   = prev.Bar.Close + diff.Bar.Close;
                tick.Bar.BarSize = prev.Bar.BarSize + diff.Bar.BarSize;
            }
            #endregion

            #region 静态数据
            if (prev.Static != null || diff.Static != null)
            {
                tick.Static = new StaticInfo();
                if (prev.Static == null)
                {
                    prev.Static = new StaticInfo();
                }
                if (diff.Static == null)
                {
                    diff.Static = new StaticInfo();
                }

                tick.Static.LowerLimitPrice = prev.Static.LowerLimitPrice + diff.Static.LowerLimitPrice;
                tick.Static.UpperLimitPrice = prev.Static.UpperLimitPrice + diff.Static.UpperLimitPrice;
                tick.Static.SettlementPrice = prev.Static.SettlementPrice + diff.Static.SettlementPrice;

                tick.Static.Symbol   = string.IsNullOrWhiteSpace(diff.Static.Symbol) ? prev.Static.Symbol : diff.Static.Symbol;
                tick.Static.Exchange = string.IsNullOrWhiteSpace(diff.Static.Exchange) ? prev.Static.Exchange : diff.Static.Exchange;
            }
            #endregion

            #region 除权除息数据
            // 没有做过差分,所以直接返回
            if (diff.Split != null)
            {
                tick.Split = diff.Split;
            }
            #endregion

            return(tick);
        }
示例#7
0
        /// <summary>
        /// 传入两个tick得到tick的差分
        /// </summary>
        /// <param name="prev"></param>
        /// <param name="current"></param>
        /// <returns></returns>
        public PbTick Diff(PbTick prev, PbTick current)
        {
            if (prev == null)
            {
                if (current.Config == null)
                {
                    throw new Exception("快照的配置不能为空");
                }

                return(current);
            }

            var tick = new PbTick();

            #region 配置数据
            // 当前数据为空或前后相同,表示
            if (current.Config == null || prev.Config.IsSame(current.Config))
            {
                tick.Config = null;
                // 可以继续下去
            }
            else
            {
                // 是新数据,返回快照
                Config = current.Config;
                return(current);
            }
            #endregion

            // 先取最关键的数据,因为前一条的config总会补成有效
            Config = prev.Config;

            tick.LastPrice = current.LastPrice - prev.LastPrice;
            tick.AskPrice1 = current.AskPrice1 - prev.AskPrice1;

            // 在这假定两个数据都是完整的
            var newPrevList = new List <DepthItem>();
            var newCurrList = new List <DepthItem>();

            // 先将两个队列变成同长
            DepthListHelper.ExpandTwoListsToSameLength(
                prev.DepthList, current.DepthList,
                int.MinValue, int.MaxValue,//这个截断工作没有做
                newPrevList, newCurrList);
            // 然后做减法,变动Size
            tick.DepthList = new List <DepthItem>();
            DepthListHelper.SizeMinusInTwoLists(newPrevList, newCurrList, tick.DepthList);

            #region 常用行情信息
            tick.Volume       = current.Volume - prev.Volume;
            tick.OpenInterest = current.OpenInterest - prev.OpenInterest;
            tick.Turnover     = current.Turnover - prev.Turnover;
            tick.AveragePrice = current.AveragePrice - prev.AveragePrice;
            tick.TradingDay   = current.TradingDay - prev.TradingDay;
            tick.ActionDay    = current.ActionDay - prev.ActionDay;

            tick.Time_HHmm      = current.Time_HHmm - prev.Time_HHmm;
            tick.Time________ff = current.Time________ff - prev.Time________ff;
            // 这个地方有区别要减去一个差,将时间再缩小
            tick.Time_____ssf__ = current.Time_____ssf__ - prev.Time_____ssf__ - _config.Time_ssf_Diff;
            tick.LocalTime_Msec = current.LocalTime_Msec - prev.LocalTime_Msec;
            #endregion

            #region Bar数据
            // Bar数据要进行差分计算
            if (current.Bar != null || prev.Bar != null)
            {
                tick.Bar = new BarInfo();
                if (current.Bar == null)
                {
                    current.Bar = new BarInfo();
                }
                if (prev.Bar == null)
                {
                    prev.Bar = new BarInfo();
                }

                tick.Bar.Open    = current.Bar.Open - prev.Bar.Open;
                tick.Bar.High    = current.Bar.High - prev.Bar.High;
                tick.Bar.Low     = current.Bar.Low - prev.Bar.Low;
                tick.Bar.Close   = current.Bar.Close - prev.Bar.Close;
                tick.Bar.BarSize = current.Bar.BarSize - prev.Bar.BarSize;

                if (tick.Bar.IsZero)
                {
                    tick.Bar = null;
                }
            }
            #endregion

            #region 静态数据
            if (current.Static != null || prev.Static != null)
            {
                tick.Static = new StaticInfo();
                if (current.Static == null)
                {
                    current.Static = new StaticInfo();
                }
                if (prev.Static == null)
                {
                    prev.Static = new StaticInfo();
                }

                tick.Static.LowerLimitPrice = current.Static.LowerLimitPrice - prev.Static.LowerLimitPrice;
                tick.Static.UpperLimitPrice = current.Static.UpperLimitPrice - prev.Static.UpperLimitPrice;
                tick.Static.SettlementPrice = current.Static.SettlementPrice - prev.Static.SettlementPrice;

                if (!string.Equals(current.Static.Exchange, prev.Static.Exchange))
                {
                    tick.Static.Exchange = current.Static.Exchange;
                }

                if (!string.Equals(current.Static.Symbol, prev.Static.Symbol))
                {
                    tick.Static.Symbol = current.Static.Symbol;
                }


                if (tick.Static.IsZero)
                {
                    tick.Static = null;
                }
            }
            #endregion

            #region 除权除息数据
            // 除权除息数据本来就是稀疏矩阵,不需要做差分
            if (current.Split != null)
            {
                tick.Split = current.Split;

                if (tick.Split.IsZero)
                {
                    tick.Split = null;
                }
            }
            #endregion

            return(tick);
        }
示例#8
0
 public PbTickCodec()
 {
     Config = new ConfigInfo().Default();
 }
示例#9
0
        public PbTick Restore(PbTick prev, PbTick diff)
        {
            if (prev == null) {
                if (diff.Config == null)
                    throw new Exception("快照的配置不能为空");
                // 记下配置,要用到
                Config = diff.Config;
                // 是快照,直接返回
                return diff;
            }

            var tick = new PbTick();

            #region 配置数据
            if (diff.Config == null) {
                // 使用上条的配置
                tick.Config = prev.Config;
            }
            else {
                // 新配置
                _config = diff.Config;

                // 是快照,直接返回
                return diff;
            }
            #endregion

            Config = tick.Config;

            tick.LastPrice = prev.LastPrice + diff.LastPrice;
            tick.AskPrice1 = prev.AskPrice1 + diff.AskPrice1;

            // 前一个是完整的,后一个是做过Size和Price的调整,如何还原
            var newPrevList = new List<DepthItem>();
            var newDiffList = new List<DepthItem>();

            // 换成同长度
            DepthListHelper.ExpandTwoListsToSameLength(
                prev.DepthList, diff.DepthList,
                int.MinValue, int.MaxValue,
                newPrevList, newDiffList);

            tick.DepthList = new List<DepthItem>();
            DepthListHelper.SizeAddInTwoLists(newPrevList, newDiffList, tick.DepthList);


            #region 常用行情信息
            tick.Volume = prev.Volume + diff.Volume;
            tick.OpenInterest = prev.OpenInterest + diff.OpenInterest;
            tick.Turnover = prev.Turnover + diff.Turnover;
            tick.AveragePrice = prev.AveragePrice + diff.AveragePrice;
            tick.TradingDay = prev.TradingDay + diff.TradingDay;
            tick.ActionDay = prev.ActionDay + diff.ActionDay;

            tick.Time_HHmm = prev.Time_HHmm + diff.Time_HHmm;
            tick.Time________ff = prev.Time________ff + diff.Time________ff;
            // 还原时间
            tick.Time_____ssf__ = prev.Time_____ssf__ + diff.Time_____ssf__ + _config.Time_ssf_Diff;
            tick.LocalTime_Msec = prev.LocalTime_Msec + diff.LocalTime_Msec;
            #endregion

            #region Bar数据
            if (prev.Bar != null || diff.Bar != null) {
                tick.Bar = new BarInfo();
                if (prev.Bar == null)
                    prev.Bar = new BarInfo();
                if (diff.Bar == null)
                    diff.Bar = new BarInfo();

                tick.Bar.Open = prev.Bar.Open + diff.Bar.Open;
                tick.Bar.High = prev.Bar.High + diff.Bar.High;
                tick.Bar.Low = prev.Bar.Low + diff.Bar.Low;
                tick.Bar.Close = prev.Bar.Close + diff.Bar.Close;
                tick.Bar.BarSize = prev.Bar.BarSize + diff.Bar.BarSize;
            }
            #endregion

            #region 静态数据
            if (prev.Static != null || diff.Static != null) {
                tick.Static = new StaticInfo();
                if (prev.Static == null)
                    prev.Static = new StaticInfo();
                if (diff.Static == null)
                    diff.Static = new StaticInfo();

                tick.Static.LowerLimitPrice = prev.Static.LowerLimitPrice + diff.Static.LowerLimitPrice;
                tick.Static.UpperLimitPrice = prev.Static.UpperLimitPrice + diff.Static.UpperLimitPrice;
                tick.Static.SettlementPrice = prev.Static.SettlementPrice + diff.Static.SettlementPrice;

                tick.Static.Symbol = string.IsNullOrWhiteSpace(diff.Static.Symbol) ? prev.Static.Symbol : diff.Static.Symbol;
                tick.Static.Exchange = string.IsNullOrWhiteSpace(diff.Static.Exchange) ? prev.Static.Exchange : diff.Static.Exchange;
            }
            #endregion

            #region 除权除息数据
            // 没有做过差分,所以直接返回
            if (diff.Split != null) {
                tick.Split = diff.Split;
            }
            #endregion

            return tick;
        }
示例#10
0
        /// <summary>
        /// 传入两个tick得到tick的差分
        /// </summary>
        /// <param name="prev"></param>
        /// <param name="current"></param>
        /// <returns></returns>
        public PbTick Diff(PbTick prev, PbTick current)
        {
            if (prev == null) {
                if (current.Config == null)
                    throw new Exception("快照的配置不能为空");

                return current;
            }

            var tick = new PbTick();

            #region 配置数据
            // 当前数据为空或前后相同,表示
            if (current.Config == null || prev.Config.IsSame(current.Config)) {
                tick.Config = null;
                // 可以继续下去
            }
            else {
                // 是新数据,返回快照
                Config = current.Config;
                return current;
            }
            #endregion

            // 先取最关键的数据,因为前一条的config总会补成有效
            Config = prev.Config;

            tick.LastPrice = current.LastPrice - prev.LastPrice;
            tick.AskPrice1 = current.AskPrice1 - prev.AskPrice1;

            // 在这假定两个数据都是完整的
            var newPrevList = new List<DepthItem>();
            var newCurrList = new List<DepthItem>();

            // 先将两个队列变成同长
            DepthListHelper.ExpandTwoListsToSameLength(
                prev.DepthList, current.DepthList,
                int.MinValue, int.MaxValue,//这个截断工作没有做
                newPrevList, newCurrList);
            // 然后做减法,变动Size
            tick.DepthList = new List<DepthItem>();
            DepthListHelper.SizeMinusInTwoLists(newPrevList, newCurrList, tick.DepthList);

            #region 常用行情信息
            tick.Volume = current.Volume - prev.Volume;
            tick.OpenInterest = current.OpenInterest - prev.OpenInterest;
            tick.Turnover = current.Turnover - prev.Turnover;
            tick.AveragePrice = current.AveragePrice - prev.AveragePrice;
            tick.TradingDay = current.TradingDay - prev.TradingDay;
            tick.ActionDay = current.ActionDay - prev.ActionDay;

            tick.Time_HHmm = current.Time_HHmm - prev.Time_HHmm;
            tick.Time________ff = current.Time________ff - prev.Time________ff;
            // 这个地方有区别要减去一个差,将时间再缩小
            tick.Time_____ssf__ = current.Time_____ssf__ - prev.Time_____ssf__ - _config.Time_ssf_Diff;
            tick.LocalTime_Msec = current.LocalTime_Msec - prev.LocalTime_Msec;
            #endregion

            #region Bar数据
            // Bar数据要进行差分计算
            if (current.Bar != null || prev.Bar != null) {
                tick.Bar = new BarInfo();
                if (current.Bar == null)
                    current.Bar = new BarInfo();
                if (prev.Bar == null)
                    prev.Bar = new BarInfo();

                tick.Bar.Open = current.Bar.Open - prev.Bar.Open;
                tick.Bar.High = current.Bar.High - prev.Bar.High;
                tick.Bar.Low = current.Bar.Low - prev.Bar.Low;
                tick.Bar.Close = current.Bar.Close - prev.Bar.Close;
                tick.Bar.BarSize = current.Bar.BarSize - prev.Bar.BarSize;

                if (tick.Bar.IsZero)
                    tick.Bar = null;
            }
            #endregion

            #region 静态数据
            if (current.Static != null || prev.Static != null) {
                tick.Static = new StaticInfo();
                if (current.Static == null)
                    current.Static = new StaticInfo();
                if (prev.Static == null)
                    prev.Static = new StaticInfo();

                tick.Static.LowerLimitPrice = current.Static.LowerLimitPrice - prev.Static.LowerLimitPrice;
                tick.Static.UpperLimitPrice = current.Static.UpperLimitPrice - prev.Static.UpperLimitPrice;
                tick.Static.SettlementPrice = current.Static.SettlementPrice - prev.Static.SettlementPrice;

                if (!string.Equals(current.Static.Exchange, prev.Static.Exchange))
                    tick.Static.Exchange = current.Static.Exchange;

                if (!string.Equals(current.Static.Symbol, prev.Static.Symbol))
                    tick.Static.Symbol = current.Static.Symbol;


                if (tick.Static.IsZero)
                    tick.Static = null;
            }
            #endregion

            #region 除权除息数据
            // 除权除息数据本来就是稀疏矩阵,不需要做差分
            if (current.Split != null) {
                tick.Split = current.Split;

                if (tick.Split.IsZero)
                    tick.Split = null;
            }
            #endregion

            return tick;
        }
示例#11
0
 public PbTickCodec()
 {
     Config = new ConfigInfo().Default();
 }
示例#12
0
        /// <summary>
        /// 将结构体的数据展开到列表中
        /// 读取出数据后立即使用展开,其它时候都不要调用
        /// 以后用户要使用数据时直接操作列表即可
        /// </summary>
        public void PrepareObjectAfterRead(ConfigInfo _Config)
        {
            if (Depth == null || Depth.IsZero)
            {
                DepthList = null;
                return;
            }

            List<DepthItem> tempList = new List<DepthItem>();

            DepthListHelper.StructToList(Depth, _Config.MarketType, tempList);
            // 不能这么写,因为还原时LastPrice还是一个很小的值
            //if (tempList.Count > 0)
            //    tempList[0].Price = LastPrice + tempList[0].Price;

            DepthList = new List<DepthItem>();
            DepthListHelper.PriceAddInOneList(tempList, DepthList);
        }
示例#13
0
        /// <summary>
        /// 将列表中的数据平铺到结构体中
        /// 只在保存到文件时操作,其它时候都不要调用
        /// 以后用户要使用数据时直接操作列表即可
        /// </summary>
        public void PrepareObjectBeforeWrite(ConfigInfo _Config)
        {
            if (DepthList == null || DepthList.Count == 0)
            {
                Depth = null;
                return;
            }

            List<DepthItem> tempList = new List<DepthItem>();

            DepthListHelper.PriceMinusInOneList(DepthList, tempList);
            

            // 还是使用新的,因为不知道以前是否已经有数据,导致混淆
            Depth = new DepthTick();
            //if(tempList.Count>0)
            //    tempList[0].Price = LastPrice - tempList[0].Price;
            DepthListHelper.ListToStruct(tempList, _Config.MarketType, Depth);
        }