private void CreateAssociatedSecurityQuotes(QuoteChangeMessage quoteMsg) { if (!SessionHolder.CreateAssociatedSecurity) { return; } if (quoteMsg.SecurityId.IsDefault()) { return; } var builder = _quoteChangeDepthBuilders .SafeAdd(quoteMsg.SecurityId.SecurityCode, c => new QuoteChangeDepthBuilder(c, SessionHolder.AssociatedBoardCode)); NewOutMessage.SafeInvoke(builder.Process(quoteMsg)); }
/// <summary> /// Отправить исходящее сообщение, вызвав событие <see cref="NewOutMessage"/>. /// </summary> /// <param name="message">Сообщение.</param> public virtual void SendOutMessage(Message message) { InitMessageLocalTime(message); if (_prevTime != DateTime.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.SafeInvoke(message); }
/// <summary> /// Open channel. /// </summary> public void Open() { _messageQueue.Open(); ThreadingHelper .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() => { while (!_messageQueue.IsClosed) { try { KeyValuePair <DateTimeOffset, Message> pair; if (!_messageQueue.TryDequeue(out pair)) { break; } //if (!(message is TimeMessage) && message.GetType().Name != "BasketMessage") // Console.WriteLine("<< ({0}) {1}", System.Threading.Thread.CurrentThread.Name, message); _msgStat.Remove(pair.Value); NewOutMessage.SafeInvoke(pair.Value); } catch (Exception ex) { _errorHandler(ex); } } Closed.SafeInvoke(); })) .Name("{0} channel thread.".Put(Name)) //.Culture(CultureInfo.InvariantCulture) .Launch(); }
public void Open() { _messageQueue.Open(); ThreadingHelper .Thread(() => CultureInfo.InvariantCulture.DoInCulture(() => { while (!_messageQueue.IsClosed) { try { var sended = _historyMessageAdapter.SendOutMessage(); KeyValuePair <DateTimeOffset, Message> pair; if (!_messageQueue.TryDequeue(out pair, true, !sended)) { if (!sended) { break; } } else { NewOutMessage.SafeInvoke(pair.Value); } } catch (Exception ex) { _errorHandler(ex); } } })) .Name("History emulation channel thread.") .Launch(); }
/// <summary> /// To call the event <see cref="NewOutMessage"/>. /// </summary> /// <param name="message">The message.</param> protected void RaiseNewOutMessage(Message message) { NewOutMessage.SafeInvoke(message); }
/// <summary> /// Метод обработки исходящих сообщений для <see cref="OutMessageProcessor"/>. /// </summary> /// <param name="message">Сообщение.</param> /// <param name="adapter">Адаптер.</param> protected virtual void OnOutMessageProcessor(Message message, IMessageAdapter adapter) { if (this != adapter) { return; } switch (message.Type) { case MessageTypes.ClearMessageQueue: OutMessageProcessor.Clear((ClearMessageQueueMessage)message); return; case MessageTypes.Security: { NewOutMessage.SafeInvoke(message); if (!SessionHolder.CreateAssociatedSecurity) { break; } var clone = (SecurityMessage)message.Clone(); clone.SecurityId = CloneSecurityId(clone.SecurityId); NewOutMessage.SafeInvoke(clone); break; } case MessageTypes.Level1Change: { NewOutMessage.SafeInvoke(message); var l1Msg = (Level1ChangeMessage)message; if (l1Msg.SecurityId.IsDefault()) { break; } if (SessionHolder.CreateAssociatedSecurity) { // обновление BestXXX для ALL из конкретных тикеров var clone = (Level1ChangeMessage)l1Msg.Clone(); clone.SecurityId = CloneSecurityId(clone.SecurityId); NewOutMessage.SafeInvoke(clone); } if (SessionHolder.CreateDepthFromLevel1) { // генерация стакана из Level1 var builder = _level1DepthBuilders.SafeAdd(l1Msg.SecurityId, c => new Level1DepthBuilder(c)); if (builder.Process(l1Msg)) { var quoteMsg = builder.QuoteChange; NewOutMessage.SafeInvoke(quoteMsg); CreateAssociatedSecurityQuotes(quoteMsg); } } break; } case MessageTypes.QuoteChange: { var quoteMsg = (QuoteChangeMessage)message; NewOutMessage.SafeInvoke(quoteMsg); if (SessionHolder.CreateDepthFromLevel1) { _level1DepthBuilders.SafeAdd(quoteMsg.SecurityId, c => new Level1DepthBuilder(c)).HasDepth = true; } CreateAssociatedSecurityQuotes(quoteMsg); break; } case MessageTypes.Execution: { NewOutMessage.SafeInvoke(message); if (!SessionHolder.CreateAssociatedSecurity) { break; } var execMsg = (ExecutionMessage)message; if (execMsg.SecurityId.IsDefault()) { break; } switch (execMsg.ExecutionType) { case ExecutionTypes.Tick: case ExecutionTypes.OrderLog: { var clone = (ExecutionMessage)message.Clone(); clone.SecurityId = CloneSecurityId(clone.SecurityId); NewOutMessage.SafeInvoke(clone); break; } } break; } default: NewOutMessage.SafeInvoke(message); break; } }
/// <summary> /// Отправить исходящее сообщение, вызвав событие <see cref="NewOutMessage"/>. /// </summary> /// <param name="message">Сообщение.</param> public virtual void SendOutMessage(Message message) { InitMessageLocalTime(message); switch (message.Type) { case MessageTypes.Security: { NewOutMessage.SafeInvoke(message); if (!CreateAssociatedSecurity) { break; } var clone = (SecurityMessage)message.Clone(); clone.SecurityId = CloneSecurityId(clone.SecurityId); NewOutMessage.SafeInvoke(clone); break; } case MessageTypes.Level1Change: { NewOutMessage.SafeInvoke(message); var l1Msg = (Level1ChangeMessage)message; if (l1Msg.SecurityId.IsDefault()) { break; } if (CreateAssociatedSecurity) { // обновление BestXXX для ALL из конкретных тикеров var clone = (Level1ChangeMessage)l1Msg.Clone(); clone.SecurityId = CloneSecurityId(clone.SecurityId); NewOutMessage.SafeInvoke(clone); } if (CreateDepthFromLevel1) { // генерация стакана из Level1 var builder = _level1DepthBuilders.SafeAdd(l1Msg.SecurityId, c => new Level1DepthBuilder(c)); if (builder.Process(l1Msg)) { var quoteMsg = builder.QuoteChange; NewOutMessage.SafeInvoke(quoteMsg); CreateAssociatedSecurityQuotes(quoteMsg); } } break; } case MessageTypes.QuoteChange: { var quoteMsg = (QuoteChangeMessage)message; NewOutMessage.SafeInvoke(quoteMsg); if (CreateDepthFromLevel1) { _level1DepthBuilders.SafeAdd(quoteMsg.SecurityId, c => new Level1DepthBuilder(c)).HasDepth = true; } CreateAssociatedSecurityQuotes(quoteMsg); break; } case MessageTypes.Execution: { NewOutMessage.SafeInvoke(message); if (!CreateAssociatedSecurity) { break; } var execMsg = (ExecutionMessage)message; if (execMsg.SecurityId.IsDefault()) { break; } switch (execMsg.ExecutionType) { case ExecutionTypes.Tick: case ExecutionTypes.OrderLog: { var clone = (ExecutionMessage)message.Clone(); clone.SecurityId = CloneSecurityId(clone.SecurityId); NewOutMessage.SafeInvoke(clone); break; } } break; } default: { if (_prevTime != DateTime.MinValue) { var diff = message.LocalTime - _prevTime; //if (message.Type != MessageTypes.Time && diff >= MarketTimeChangedInterval) //{ // SendOutMessage(new TimeMessage // { // LocalTime = message.LocalTime, // ServerTime = message.GetServerTime(), // }); //} _secLookupTimeOut .ProcessTime(diff) .ForEach(id => SendOutMessage(new SecurityLookupResultMessage { OriginalTransactionId = id })); _pfLookupTimeOut .ProcessTime(diff) .ForEach(id => SendOutMessage(new PortfolioLookupResultMessage { OriginalTransactionId = id })); //ProcessReconnection(diff); } _prevTime = message.LocalTime; NewOutMessage.SafeInvoke(message); break; } } }
private void TransactionAdapterOnNewOutMessage(Message message) { NewOutMessage.SafeInvoke(message); }
private void MarketDataAdapterOnNewOutMessage(Message message) { NewOutMessage.SafeInvoke(message); }