Example #1
0
        public RequestStatus SendNewOrderRequest(Account account,
                                                 MarketOrder order,
                                                 OrderType orderType,
                                                 decimal requestedPrice,
                                                 decimal slippagePoints)
        {
            TradeSharp.ProviderProxyContract.Entity.MarketOrder request;
            RequestStatus error;

            if (!MakeMarketRequest(account, order.Symbol, order.Magic, order.Volume, order.Side,
                                   orderType,
                                   requestedPrice, slippagePoints,
                                   string.Format("open for acc#{0}", account.ID),
                                   null, order.Comment, order.ExpertComment, order.trailingLevels[0], order.trailingTargets[0],
                                   out error, out request))
            {
                return(error);
            }

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

            try
            {
                locker.AcquireReaderLock(LockTimeout);
            }
            catch
            {
                return;
            }
            try
            {
                var nowTime = DateTime.Now;
                if (!requests.Any(r => (nowTime - r.requestTime).TotalMilliseconds > milsToReportError))
                {
                    return;
                }
                locker.UpgradeToWriterLock(LockTimeout);
                for (var i = 0; i < requests.Count; i++)
                {
                    var req = requests[i];
                    if ((nowTime - req.requestTime).TotalMilliseconds > milsToReportError)
                    {
                        requests.RemoveAt(i);
                        i--;
                        errors.Add(new ErrorMessage(DateTime.Now, ErrorMessageType.НетОтвета,
                                                    string.Format("Запрос {0} ({1} {2}) устарел на {3} ms",
                                                                  req.requestId,
                                                                  req.requestType, req.requestSymbol, milsToReportError),
                                                    null));
                    }
                }
            }
            finally
            {
                locker.ReleaseLock();
            }
            if (errors.Count == 0)
            {
                return;
            }
            foreach (var er in errors)
            {
                errorStorage.AddMessage(er);
            }
        }