public int RegisterOrder(OrderRegisterMessage message) { var marketTime = _ad.SessionTime; var secCode = message.SecurityId.SecurityCode; var account = message.PortfolioName.AccountFromPortfolioName(); // Портфель var placeCode = _adapter.SecurityClassInfo.GetSecurityClass(message.SecurityType, message.SecurityId.BoardCode); var endDate = (message.TillDate == null || message.TillDate == DateTimeOffset.MaxValue ? marketTime.Date.AddTicks(new TimeSpan(23, 55, 00).Ticks) : message.TillDate.Value).ToLocalTime(TimeHelper.Moscow); // Срок действия поручения. var maxEndDate = DateTime.Now + TimeSpan.FromDays(365); if (endDate > maxEndDate) { endDate = maxEndDate; } var comments = message.TransactionId.To <string>(); // Комментарий. var currency = message.Currency == null || message.Currency == CurrencyTypes.RUB ? "RUR" : message.Currency.ToString(); //_securityCurrencies[message.SecurityId.SecurityCode]; // Валюта цены. var buySell = message.Side.ToAlfaDirect(); // Покупка/Продажа var quantity = (int)message.Volume; // Количество. var price = message.Price; // Цена. int id; _adapter.AddInfoLog("Register: {0} {1}/{2} tran={3} {4} {5}@{6}, mtime={7}, cur={8}", account, secCode, placeCode, comments, buySell, quantity, price, marketTime, currency); if (placeCode == null) { throw new InvalidOperationException(LocalizedStrings.Str2274Params.Put(message.TransactionId)); } if (message.OrderType == OrderTypes.Conditional) { var condition = (AlfaOrderCondition)message.Condition; if (condition.TargetPrice != 0) { id = _ad.CreateStopOrder(account, placeCode, secCode, endDate, comments, currency, buySell, quantity, (double)condition.StopPrice, (double)condition.Slippage, condition.TargetPrice, -1); } else if (condition.Level != 0) { id = _ad.CreateTrailingOrder(account, placeCode, secCode, endDate, comments, currency, buySell, quantity, (double)condition.StopPrice, (double)condition.Level, (double)condition.Slippage, -1); } else { id = _ad.CreateStopOrder(account, placeCode, secCode, endDate, comments, currency, buySell, quantity, (double)condition.StopPrice, (double)condition.Slippage, null, -1); } } else { if (message.OrderType == OrderTypes.Market) { throw new InvalidOperationException(LocalizedStrings.Str2275); } id = _ad.CreateLimitOrder(account, placeCode, secCode, endDate, comments, currency, buySell, quantity, (double)price, null, null, null, null, null, "Y", null, null, null, null, null, null, null, null, null, null, -1); } if (id == 0) { ThrowInError(tagStateCodes.stcClientError, LocalizedStrings.Str2276Params.Put(message.TransactionId, _ad.LastResultMsg)); } return(id); }