/// <summary> /// Обработать сообщение. /// </summary> /// <param name="message">Сообщение.</param> public void Process(Message message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } LogReceiver.AddDebugLog("Out. {0}", message); switch (message.Type) { case MessageTypes.Level1Change: { var l1Msg = (Level1ChangeMessage)message; lock (_prevLevel1.SyncRoot) { var prevLevel1 = _prevLevel1.TryGetValue(l1Msg.SecurityId); if (prevLevel1 == null) { _prevLevel1.Add(l1Msg.SecurityId, (Level1ChangeMessage)l1Msg.Clone()); } else { l1Msg.Changes.RemoveWhere(p => { var prevValue = prevLevel1.Changes.TryGetValue(p.Key); if (prevValue != null && prevValue.Equals(p.Value)) { return(true); } prevLevel1.Changes[p.Key] = p.Value; return(false); }); if (l1Msg.Changes.Count == 0) { return; } } } ReplaceSecurityId(l1Msg.SecurityId, id => l1Msg.SecurityId = id); break; } case MessageTypes.Security: { var secMsg = (SecurityMessage)message; var classCode = secMsg.SecurityId.BoardCode; var classInfo = _securityClassInfo.GetSecurityClassInfo(classCode); // из квика не транслируется поле тип инструмента, если тип инструмента не найден по классу, то берем по умолчанию. secMsg.SecurityType = secMsg.Multiplier == 0 ? SecurityTypes.Index : (classInfo.Item1 ?? SecurityTypes.Stock); ReplaceSecurityId(secMsg.SecurityId, id => secMsg.SecurityId = id); break; } case MessageTypes.QuoteChange: { var quoteMsg = (QuoteChangeMessage)message; ReplaceSecurityId(quoteMsg.SecurityId, id => quoteMsg.SecurityId = id); break; } case MessageTypes.Execution: { var execMsg = (ExecutionMessage)message; if (execMsg.ExecutionType == ExecutionTypes.Order) { if (execMsg.OrderId != null) { if (execMsg.TransactionId == 0) { // TODO // автоинкремент проставляется для ручных заявок, но возникает баг, // что и для заявок робота может приходить нулевой идентификатор // https://forum.quik.ru/forum10/topic870/ // // execMsg.TransactionId = GetNextTransactionId(); } else { _fixServer.AddTransactionId(execMsg.TransactionId); } _fixServer.AddTransactionId(execMsg.OriginalTransactionId); } var transaction = _transactions.TryGetValue(execMsg.OriginalTransactionId); if (transaction != null && execMsg.Error != null) { switch (transaction.TransactionType) { //case TransactionTypes.ReRegister: //{ // var replaceMsg = (OrderReplaceMessage)transaction.Message; // // дополнительно отправляем сообщение ошибки снятия заявки // var cancelErrMsg = (ExecutionMessage)execMsg.Clone(); // cancelErrMsg.OrderId = replaceMsg.OldOrderId; // cancelErrMsg.IsCancelled = true; // break; //} case TransactionTypes.Cancel: { var cancelMsg = (OrderCancelMessage)transaction.Message; // заполняем номер заявки execMsg.OrderId = cancelMsg.OrderId; execMsg.IsCancelled = true; break; } } } } ReplaceSecurityId(execMsg.SecurityId, id => execMsg.SecurityId = id); break; } case MessageTypes.Portfolio: { var pfMsg = (PortfolioMessage)message; ReplaceBoardCode(pfMsg.BoardCode, board => pfMsg.BoardCode = board); break; } case MessageTypes.PortfolioChange: { var pfMsg = (PortfolioChangeMessage)message; ReplaceBoardCode(pfMsg.BoardCode, board => pfMsg.BoardCode = board); var depoName = (string)pfMsg.Changes.TryGetValue(PositionChangeTypes.DepoName); if (!depoName.IsEmpty()) { _depoNames[pfMsg.PortfolioName] = depoName; } break; } case MessageTypes.Position: { var pfMsg = (PositionMessage)message; ReplaceSecurityId(pfMsg.SecurityId, id => pfMsg.SecurityId = id); break; } case MessageTypes.PositionChange: { var pfMsg = (PositionChangeMessage)message; ReplaceSecurityId(pfMsg.SecurityId, id => pfMsg.SecurityId = id); break; } } _fixServer.SendInMessage(message); }
/// <summary> /// Добавить ассоциацию идентификатора запроса и транзакции. /// </summary> /// <param name="transactionId">Идентификатор транзакции.</param> public void AddTransactionId(long transactionId) { _fixServer.AddTransactionId(transactionId); }
/// <summary> /// Добавить ассоциацию идентификатора запроса и транзакции. /// </summary> /// <param name="transactionId">Идентификатор транзакции.</param> public void AddTransactionId(long transactionId) { LogReceiver.AddInfoLog("Added trans id {0} mapping.", transactionId); _fixServer.AddTransactionId(Login, transactionId, transactionId); }