Example #1
0
        public RequestStatus SendCloseRequest(MarketOrder order, PositionExitReason reason)
        {
            // получить счет
            RequestStatus error;
            var           acDecorated = ServerInterface.GetAccount(order.AccountID);

            if (acDecorated == null)
            {
                return(RequestStatus.ServerError);
            }

            // подготовить запрос
            TradeSharp.ProviderProxyContract.Entity.MarketOrder request;
            if (!MakeMarketRequest(acDecorated, order.Symbol, order.Magic, order.Volume, -order.Side,
                                   OrderType.Market,
                                   0, 0,
                                   string.Format("close order #{0}", order.ID),
                                   order.ID, order.Comment, order.ExpertComment, order.TrailLevel1, order.TrailTarget1,
                                   out error, out request))
            {
                return(error);
            }
            exitReasonByOrderId.UpdateValues(order.ID, reason);

            // отправить запрос на вход в рынок (оно же - закрытие позиции) в соотв сессию
            if (!request.SendToQueue(false))
            {
                errorStorage.AddMessage(new ErrorMessage(DateTime.Now, ErrorMessageType.ОшибкаОтправки,
                                                         "Невозможно отправить сообщение (CloseOrder) в очередь MQ", null));
                return(RequestStatus.DealerError);
            }
            return(RequestStatus.OK);
        }