Exemple #1
0
        /// <summary>
        /// Helper.
        /// </summary>
        protected RequiredType GetPendingMessage <RequiredType>(bool startOperation, out int id)
            where RequiredType : RequestMessage
        {
            id = 0;

            try
            {
                lock (this)
                {
                    foreach (OperationInformation info in _stub.PendingOperationsArray)
                    {
                        if (info.Request is RequiredType && info.IsStarted == false)
                        {
                            TracerHelper.Trace("Executing " + info.Request.GetType().Name + " requested was " + typeof(RequiredType).Name);

                            id = Int32.Parse(info.Id);

                            if (startOperation)
                            {
                                info.Start();

                                if (((RequestMessage)info.Request).PerformSynchronous == false)
                                {// Finish of operations that do not require responces as soon as they are started.
                                    TracerHelper.Trace("Completing " + info.Request.GetType().Name);
                                    _stub.CompleteOperation(info.Id, null);
                                }
                            }


                            return((RequiredType)info.Request);
                        }
                    }
                }
            }
            catch (Exception ex)
            {// Make sure we handle any possible unexpected exceptions, as otherwise they bring the
                // entire package (MT4 included) down with a bad error.
                SystemMonitor.Error(ex.Message);
            }

            return(null);
        }
        /// <summary>
        ///
        /// </summary>
        void _historyClient_OnDataEvent(int lRequestId, object pHist, enumHistEventType evt)
        {
            List <DataBar> extractedBars = new List <DataBar>();

            if (pHist is MbtHistDayBar)
            {
                MbtHistDayBar bars = (MbtHistDayBar)pHist;
                bars.First();

                while (bars.Eof == false)
                {
                    decimal open  = (decimal)bars.Open;
                    decimal close = (decimal)bars.Close;
                    decimal high  = (decimal)bars.High;
                    decimal low   = (decimal)bars.Low;

                    extractedBars.Insert(0, new DataBar(bars.CloseDate, open, high, low, close, bars.TotalVolume));
                    bars.Next();
                }
            }
            else if (pHist is MbtHistMinBar)
            {
                MbtHistMinBar bars = (MbtHistMinBar)pHist;
                bars.First();

                while (bars.Eof == false)
                {
                    decimal open  = (decimal)bars.Open;
                    decimal close = (decimal)bars.Close;
                    decimal high  = (decimal)bars.High;
                    decimal low   = (decimal)bars.Low;

                    extractedBars.Insert(0, new DataBar(bars.UTCDateTime, open, high, low, close, bars.TotalVolume));
                    bars.Next();
                }
            }

            DataHistoryOperation operation = (DataHistoryOperation)_operationStub.GetOperationById(lRequestId.ToString());

            if (operation != null)
            {
                _operationStub.CompleteOperation(lRequestId.ToString(), new DataHistoryUpdate(operation.Request.Period, extractedBars));
            }
        }