public IEnumerable <OrderChangeInfo> ApplyChanges(ExecutionMessage message, bool isCancel, Action <Order> process) { if (process is null) { throw new ArgumentNullException(nameof(process)); } var order = Order; OrderChangeInfo retVal; if (order.State == OrderStates.Done) { // данные о заявке могут приходить из маркет-дата и транзакционного адаптеров retVal = new OrderChangeInfo(order, _raiseNewOrder, false); _raiseNewOrder = false; process(order); yield return(retVal); //throw new InvalidOperationException("Изменение заявки в состоянии Done невозможно."); } else if (order.State == OrderStates.Failed) { // some adapters can resend order's info //throw new InvalidOperationException(); yield break; } var isPending = order.State == OrderStates.Pending; // is we have Pending order and received Done event // add intermediate Active event if (isPending && message.OrderState == OrderStates.Done) { var clone = message.TypedClone(); clone.OrderState = OrderStates.Active; clone.Balance = null; foreach (var i in ApplyChanges(clone, false, process)) { yield return(i); } } if (message.OrderId != null) { order.Id = message.OrderId.Value; } if (!message.OrderStringId.IsEmpty()) { order.StringId = message.OrderStringId; } if (!message.OrderBoardId.IsEmpty()) { order.BoardId = message.OrderBoardId; } if (message.Balance != null) { order.Balance = ((decimal?)order.Balance).ApplyNewBalance(message.Balance.Value, order.TransactionId, _parent._logReceiver); } if (message.OrderState != null) { order.ApplyNewState(message.OrderState.Value, _parent._logReceiver); } if (order.Time == DateTimeOffset.MinValue) { order.Time = message.ServerTime; } // для новых заявок используем серверное время, // т.к. заявка получена первый раз и не менялась // ServerTime для заявки - это время регистрации order.LastChangeTime = _raiseNewOrder ? message.ServerTime : message.LocalTime; order.LocalTime = message.LocalTime; //нулевой объем может быть при перерегистрации if (order.Volume == 0 && message.OrderVolume != null) { order.Volume = message.OrderVolume.Value; } if (message.Commission != null) { order.Commission = message.Commission; } if (!message.CommissionCurrency.IsEmpty()) { order.CommissionCurrency = message.CommissionCurrency; } if (message.TimeInForce != null) { order.TimeInForce = message.TimeInForce.Value; } if (message.Latency != null) { if (isCancel) { order.LatencyCancellation = message.Latency.Value; } else if (isPending) { if (order.State != OrderStates.Pending) { order.LatencyRegistration = message.Latency.Value; } } } if (message.AveragePrice != null) { order.AveragePrice = message.AveragePrice; } if (message.Yield != null) { order.Yield = message.Yield; } message.CopyExtensionInfo(order); retVal = new OrderChangeInfo(order, _raiseNewOrder, true); _raiseNewOrder = false; process(order); yield return(retVal); }