示例#1
0
        /// <summary>
        /// Send outgoing message and raise <see cref="MessageAdapter.NewOutMessage"/> event.
        /// </summary>
        /// <param name="message">Message.</param>
        public virtual void SendOutMessage(Message message)
        {
            InitMessageLocalTime(message);

            if (message.IsBack && message.Adapter == null)
            {
                message.Adapter = this;
            }

            if (_prevTime != DateTimeOffset.MinValue)
            {
                var diff = message.LocalTime - _prevTime;

                _secLookupTimeOut
                .ProcessTime(diff)
                .ForEach(id => SendOutMessage(new SecurityLookupResultMessage {
                    OriginalTransactionId = id
                }));

                _pfLookupTimeOut
                .ProcessTime(diff)
                .ForEach(id => SendOutMessage(new PortfolioLookupResultMessage {
                    OriginalTransactionId = id
                }));
            }

            _prevTime = message.LocalTime;
            NewOutMessage?.Invoke(message);
        }
示例#2
0
            public void Open()
            {
                _messageQueue.Open();

                ThreadingHelper
                .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() =>
                {
                    while (!_messageQueue.IsClosed)
                    {
                        try
                        {
                            var sended    = _historyMessageAdapter.SendOutMessage();
                            var processed = false;

                            while (_messageQueue.TryDequeue(out var message, true, false))
                            {
                                NewOutMessage?.Invoke(message);
                                processed = true;
                            }

                            if (!sended && !processed && !_messageQueue.IsClosed)
                            {
                                Thread.Sleep(100);
                            }
                        }
                        catch (Exception ex)
                        {
                            _errorHandler(ex);
                        }
                    }
                }))
                .Name("History emulation channel thread.")
                .Launch();
            }
示例#3
0
            public void Open()
            {
                _messageQueue.Open();

                ThreadingHelper
                .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() =>
                {
                    while (!_messageQueue.IsClosed)
                    {
                        try
                        {
                            var sended = _historyMessageAdapter.SendOutMessage();

                            Message message;

                            if (!_messageQueue.TryDequeue(out message, true, !sended))
                            {
                                if (!sended)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                NewOutMessage?.Invoke(message);
                            }
                        }
                        catch (Exception ex)
                        {
                            _errorHandler(ex);
                        }
                    }
                }))
                .Name("History emulation channel thread.")
                .Launch();
            }
示例#4
0
        /// <summary>
        /// Open channel.
        /// </summary>
        public void Open()
        {
            _messageQueue.Open();

            ThreadingHelper
            .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() =>
            {
                while (!_messageQueue.IsClosed)
                {
                    try
                    {
                        Message message;

                        if (!_messageQueue.TryDequeue(out message))
                        {
                            break;
                        }

                        //if (!(message is TimeMessage) && message.GetType().Name != "BasketMessage")
                        //	Console.WriteLine("<< ({0}) {1}", System.Threading.Thread.CurrentThread.Name, message);

                        _msgStat.Remove(message);
                        NewOutMessage?.Invoke(message);
                    }
                    catch (Exception ex)
                    {
                        _errorHandler(ex);
                    }
                }

                Closed?.Invoke();
            }))
            .Name($"{Name} channel thread.")
            //.Culture(CultureInfo.InvariantCulture)
            .Launch();
        }
示例#5
0
 /// <summary>
 /// To call the event <see cref="NewOutMessage"/>.
 /// </summary>
 /// <param name="message">The message.</param>
 protected void RaiseNewOutMessage(Message message)
 {
     NewOutMessage?.Invoke(message);
 }