Beispiel #1
0
        private void UpdatePriceLevel(CandlePriceLevel level, ICandleBuilderSourceValue value)
        {
            if (level == null)
            {
                throw new ArgumentNullException(nameof(level));
            }

            //var side = value.OrderDirection;

            //if (side == null)
            //	throw new ArgumentException(nameof(value));

            level.TotalVolume += value.Volume;

            if (value.OrderDirection == Sides.Buy)
            {
                level.BuyVolume += value.Volume;
                level.BuyCount++;

                ((List <decimal>)level.BuyVolumes).Add(value.Volume);
            }
            else if (value.OrderDirection == Sides.Sell)
            {
                level.SellVolume += value.Volume;
                level.SellCount++;

                ((List <decimal>)level.SellVolumes).Add(value.Volume);
            }
        }
Beispiel #2
0
        private CandlePriceLevel GetPriceLevel(decimal price)
        {
            return(_volumeProfileInfo.SafeAdd(price, key =>
            {
                var level = new CandlePriceLevel
                {
                    Price = key,
                    BuyVolumes = new List <decimal>(),
                    SellVolumes = new List <decimal>()
                };

                ((IList <CandlePriceLevel>)PriceLevels).Add(level);

                return level;
            }));
        }
Beispiel #3
0
        /// <summary>
        /// To update the profile with new value.
        /// </summary>
        /// <param name="priceLevel">Value.</param>
        public void Update(CandlePriceLevel priceLevel)
        {
            var level = GetPriceLevel(priceLevel.Price);

            level.BuyVolume  += priceLevel.BuyVolume;
            level.BuyCount   += priceLevel.BuyCount;
            level.SellVolume += priceLevel.SellVolume;
            level.SellCount  += priceLevel.SellCount;

            if (priceLevel.BuyVolumes != null)
            {
                ((List <decimal>)level.BuyVolumes).AddRange(priceLevel.BuyVolumes);
            }

            if (priceLevel.SellVolumes != null)
            {
                ((List <decimal>)level.SellVolumes).AddRange(priceLevel.SellVolumes);
            }
        }
Beispiel #4
0
        public override TCandleMessage MoveNext(MarketDataEnumerator enumerator)
        {
            var reader   = enumerator.Reader;
            var metaInfo = enumerator.MetaInfo;

            var candle = new TCandleMessage
            {
                SecurityId     = SecurityId,
                TotalVolume    = reader.ReadVolume(metaInfo),
                RelativeVolume = metaInfo.Version < MarketDataVersions.Version52 || !reader.Read() ? (decimal?)null : reader.ReadVolume(metaInfo),
                Arg            = Arg
            };

            var prevTime         = metaInfo.FirstTime;
            var allowNonOrdered  = metaInfo.Version >= MarketDataVersions.Version49;
            var isUtc            = metaInfo.Version >= MarketDataVersions.Version50;
            var timeZone         = metaInfo.GetTimeZone(isUtc, SecurityId, ExchangeInfoProvider);
            var allowDiffOffsets = metaInfo.Version >= MarketDataVersions.Version53;
            var useLevels        = metaInfo.Version >= MarketDataVersions.Version54;
            var isTickPrecision  = metaInfo.Version >= MarketDataVersions.Version57;
            var useLong          = metaInfo.Version >= MarketDataVersions.Version58;
            var buildFrom        = metaInfo.Version >= MarketDataVersions.Version59;
            var seqNum           = metaInfo.Version >= MarketDataVersions.Version60;

            if (metaInfo.Version < MarketDataVersions.Version56)
            {
                var prevPrice = metaInfo.FirstPrice;
                candle.LowPrice     = reader.ReadPrice(ref prevPrice, metaInfo);
                metaInfo.FirstPrice = prevPrice;

                prevPrice        = metaInfo.FirstPrice;
                candle.OpenPrice = reader.ReadPrice(ref prevPrice, metaInfo);

                prevPrice         = metaInfo.FirstPrice;
                candle.ClosePrice = reader.ReadPrice(ref prevPrice, metaInfo);

                prevPrice        = metaInfo.FirstPrice;
                candle.HighPrice = reader.ReadPrice(ref prevPrice, metaInfo);
            }
            else
            {
                candle.LowPrice = reader.ReadPriceEx(metaInfo, useLong);

                if (reader.Read())
                {
                    candle.OpenPrice  = reader.ReadPriceEx(metaInfo, useLong);
                    candle.ClosePrice = reader.ReadPriceEx(metaInfo, useLong);
                }
                else
                {
                    candle.ClosePrice = reader.ReadPriceEx(metaInfo, useLong);
                    candle.OpenPrice  = reader.ReadPriceEx(metaInfo, useLong);
                }

                candle.HighPrice = reader.ReadPriceEx(metaInfo, useLong);
            }

            var lastOffset = metaInfo.FirstServerOffset;

            candle.OpenTime            = reader.ReadTime(ref prevTime, allowNonOrdered, isUtc, timeZone, allowDiffOffsets, isTickPrecision, ref lastOffset);
            metaInfo.FirstServerOffset = lastOffset;

            if (metaInfo.Version >= MarketDataVersions.Version46)
            {
                if (reader.Read())
                {
                    var isOrdered = reader.Read();

                    var first  = reader.ReadTime(ref prevTime, allowNonOrdered, isUtc, timeZone, allowDiffOffsets, isTickPrecision, ref lastOffset);
                    var second = reader.ReadTime(ref prevTime, allowNonOrdered, isUtc, timeZone, allowDiffOffsets, isTickPrecision, ref lastOffset);

                    candle.HighTime = isOrdered ? first : second;
                    candle.LowTime  = isOrdered ? second : first;
                }
                else
                {
                    if (reader.Read())
                    {
                        candle.HighTime = reader.ReadTime(ref prevTime, allowNonOrdered, isUtc, timeZone, allowDiffOffsets, isTickPrecision, ref lastOffset);
                    }

                    if (reader.Read())
                    {
                        candle.LowTime = reader.ReadTime(ref prevTime, allowNonOrdered, isUtc, timeZone, allowDiffOffsets, isTickPrecision, ref lastOffset);
                    }
                }
            }

            if (metaInfo.Version >= MarketDataVersions.Version47)
            {
                if (reader.Read())
                {
                    candle.CloseTime = reader.ReadTime(ref prevTime, allowNonOrdered, isUtc, timeZone, allowDiffOffsets, isTickPrecision, ref lastOffset);
                }
            }
            else
            {
                candle.CloseTime = reader.ReadTime(ref prevTime, allowNonOrdered, isUtc, metaInfo.LocalOffset, allowDiffOffsets, false, ref lastOffset);
            }

            if (metaInfo.Version >= MarketDataVersions.Version46)
            {
                if (metaInfo.Version < MarketDataVersions.Version51)
                {
                    candle.OpenVolume  = reader.ReadVolume(metaInfo);
                    candle.HighVolume  = reader.ReadVolume(metaInfo);
                    candle.LowVolume   = reader.ReadVolume(metaInfo);
                    candle.CloseVolume = reader.ReadVolume(metaInfo);
                }
                else
                {
                    candle.OpenVolume  = reader.Read() ? reader.ReadVolume(metaInfo) : (decimal?)null;
                    candle.HighVolume  = reader.Read() ? reader.ReadVolume(metaInfo) : (decimal?)null;
                    candle.LowVolume   = reader.Read() ? reader.ReadVolume(metaInfo) : (decimal?)null;
                    candle.CloseVolume = reader.Read() ? reader.ReadVolume(metaInfo) : (decimal?)null;
                }
            }

            candle.State = (CandleStates)reader.ReadInt();

            metaInfo.FirstTime = metaInfo.Version <= MarketDataVersions.Version40 ? candle.OpenTime.LocalDateTime : prevTime;

            if (metaInfo.Version >= MarketDataVersions.Version45)
            {
                if (metaInfo.Version < MarketDataVersions.Version48 || reader.Read())
                {
                    candle.OpenInterest = reader.ReadVolume(metaInfo);
                }
            }

            if (metaInfo.Version >= MarketDataVersions.Version52)
            {
                candle.DownTicks  = reader.Read() ? reader.ReadInt() : (int?)null;
                candle.UpTicks    = reader.Read() ? reader.ReadInt() : (int?)null;
                candle.TotalTicks = reader.Read() ? reader.ReadInt() : (int?)null;
            }

            if (!useLevels)
            {
                return(candle);
            }

            if (reader.Read())
            {
                var priceLevels = new CandlePriceLevel[reader.ReadInt()];

                for (var i = 0; i < priceLevels.Length; i++)
                {
                    var prevPrice = metaInfo.FirstPrice;

                    var priceLevel = new CandlePriceLevel
                    {
                        Price = metaInfo.Version < MarketDataVersions.Version56
                                                                ? reader.ReadPrice(ref prevPrice, metaInfo)
                                                                : reader.ReadPriceEx(metaInfo),
                        BuyCount   = reader.ReadInt(),
                        SellCount  = reader.ReadInt(),
                        BuyVolume  = reader.ReadVolume(metaInfo),
                        SellVolume = reader.ReadVolume(metaInfo)
                    };

                    if (metaInfo.Version >= MarketDataVersions.Version55)
                    {
                        priceLevel.TotalVolume = reader.ReadVolume(metaInfo);
                    }

                    if (reader.Read())
                    {
                        var volumes = new decimal[reader.ReadInt()];

                        for (var j = 0; j < volumes.Length; j++)
                        {
                            volumes[j] = reader.ReadVolume(metaInfo);
                        }

                        priceLevel.BuyVolumes = volumes;
                    }

                    if (reader.Read())
                    {
                        var volumes = new decimal[reader.ReadInt()];

                        for (var j = 0; j < volumes.Length; j++)
                        {
                            volumes[j] = reader.ReadVolume(metaInfo);
                        }

                        priceLevel.SellVolumes = volumes;
                    }

                    priceLevels[i] = priceLevel;
                }

                candle.PriceLevels = priceLevels;
            }

            if (!buildFrom)
            {
                return(candle);
            }

            candle.BuildFrom = reader.ReadBuildFrom();

            if (!seqNum)
            {
                return(candle);
            }

            reader.ReadSeqNum(candle, metaInfo);

            return(candle);
        }
Beispiel #5
0
		private void UpdatePriceLevel(CandlePriceLevel level, ICandleBuilderSourceValue value)
		{
			if (level == null)
				throw new ArgumentNullException(nameof(level));

			var side = value.OrderDirection;

			if (side == null)
				throw new ArgumentException(nameof(value));

			if (side == Sides.Buy)
			{
				level.BuyVolume += value.Volume;
				level.BuyCount++;

				((List<decimal>)level.BuyVolumes).Add(value.Volume);
			}
			else
			{
				level.SellVolume += value.Volume;
				level.SellCount++;

				((List<decimal>)level.SellVolumes).Add(value.Volume);
			}
		}
Beispiel #6
0
		private CandlePriceLevel GetPriceLevel(decimal price)
		{
			return _volumeProfileInfo.SafeAdd(price, key =>
			{
				var level = new CandlePriceLevel
				{
					Price = key,
					BuyVolumes = new List<decimal>(),
					SellVolumes = new List<decimal>()
				};

				((IList<CandlePriceLevel>)PriceLevels).Add(level);

				return level;
			});
		}
Beispiel #7
0
		/// <summary>
		/// To update the profile with new value.
		/// </summary>
		/// <param name="priceLevel">Value.</param>
		public void Update(CandlePriceLevel priceLevel)
		{
			var level = GetPriceLevel(priceLevel.Price);

			level.BuyVolume += priceLevel.BuyVolume;
			level.BuyCount += priceLevel.BuyCount;
			level.SellVolume += priceLevel.SellVolume;
			level.SellCount += priceLevel.SellCount;

			if (priceLevel.BuyVolumes != null)
				((List<decimal>)level.BuyVolumes).AddRange(priceLevel.BuyVolumes);

			if (priceLevel.SellVolumes != null)
				((List<decimal>)level.SellVolumes).AddRange(priceLevel.SellVolumes);
		}
 /// <summary>
 /// Parses string representation of candle price level into object.
 /// </summary>
 /// <param name="s">The string representation of candle price level attribute.</param>
 /// <returns>The new candle price level attribute</returns>
 public static ICandleSymbolAttribute Parse(string s)
 {
     return(CandlePriceLevel.Parse(s));
 }
 /// <summary>
 /// Creates a new candle price level attribute with certain value
 /// </summary>
 /// <param name="priceLevel">The price level value</param>
 /// <returns>The new price level attribute</returns>
 public static ICandleSymbolAttribute NewPriceLevel(double priceLevel)
 {
     return(CandlePriceLevel.ValueOf(priceLevel));
 }