Beispiel #1
0
        /// <summary>
        /// Create a copy of <see cref="NewsMessage"/>.
        /// </summary>
        /// <returns>Copy.</returns>
        public override Message Clone()
        {
            var clone = new NewsMessage
            {
                Id         = Id,
                BoardCode  = BoardCode,
                SecurityId = SecurityId,
                Source     = Source,
                Headline   = Headline,
                Story      = Story,
                ServerTime = ServerTime,
                Url        = Url,
                Priority   = Priority,
            };

            CopyTo(clone);

            return(clone);
        }
Beispiel #2
0
		public Tuple<News, bool> ProcessNewsMessage(Security security, NewsMessage message)
		{
			if (message == null)
				throw new ArgumentNullException(nameof(message));

			var isNew = false;

			News news;

			if (!message.Id.IsEmpty())
			{
				news = _newsById.SafeAdd(message.Id, key =>
				{
					isNew = true;
					var n = EntityFactory.CreateNews();
					n.Id = key;
					return n;
				});
			}
			else
			{
				isNew = true;

				news = EntityFactory.CreateNews();
				_newsWithoutId.Add(news);
			}

			if (isNew)
			{
				news.ServerTime = message.ServerTime;
				news.LocalTime = message.LocalTime;
			}

			if (!message.Source.IsEmpty())
				news.Source = message.Source;

			if (!message.Headline.IsEmpty())
				news.Headline = message.Headline;

			if (security != null)
				news.Security = security;

			if (!message.Story.IsEmpty())
				news.Story = message.Story;

			if (!message.BoardCode.IsEmpty())
				news.Board = ExchangeBoard.GetOrCreateBoard(message.BoardCode);

			if (message.Url != null)
				news.Url = message.Url;

			message.CopyExtensionInfo(news);

			return Tuple.Create(news, isNew);
		}
		private static NewsMessage ToNewsMessage(string value)
		{
			var parts = value.SplitByComma();

			var msg = new NewsMessage
			{
				Source = parts[0],
				Id = parts[1],
				ServerTime = parts[3].ToDateTime("yyyyMMdd HHmmss").ApplyTimeZone(TimeHelper.Est),
				Headline = parts[4],
			};

			// новость может приходит без указания инструмента
			if (parts[2].IsEmpty())
				return msg;

			var symbols = parts[2].Split(":");

			if (symbols.Length > 0)
			{
				msg.ExtensionInfo = new Dictionary<object, object>
				{
					{ "Symbols", symbols }
				};
			}

			return msg;
		}
		private static NewsMessage ToNewsMessage(string value)
		{
			var parts = value.SplitByComma();

			var timeFormat = parts[3].Contains(' ') ? "yyyyMMdd HHmmss" : "yyyyMMddHHmmss";

			var msg = new NewsMessage
			{
				Source = parts[0],
				Id = parts[1],
				ServerTime = parts[3].ToDateTime(timeFormat).ApplyTimeZone(TimeHelper.Est),
				Headline = parts[4],
			};

			// news received without associated instrument
			if (parts[2].IsEmpty())
				return msg;

			var symbols = parts[2].Split(":");

			if (symbols.Length > 0)
			{
				msg.ExtensionInfo = new Dictionary<object, object>
				{
					{ "Symbols", symbols }
				};
			}

			return msg;
		}