Example #1
0
        public void FakeCQG_TimedBarsRequest()
        {
            // arrange
            UnitTestHelper.StartUp();
            #region Timer
            Timer timer = new Timer();
            timer.Interval  = 30;
            timer.AutoReset = true;
            timer.Elapsed  += Timer_Elapsed;
            timer.Start();
            #endregion
            CQGCEL fakeCQGCel = new CQGCELClass();
            Core.LogChange += CQG_LogChange;
            CQGTimedBarsRequest m_TimedBarsRequest;
            CQGTimedBars        CQGTimedBars;
            var startTime = new DateTime(2016, 06, 06);
            List <eTimedBarsRequestOutputs> TimedBarsRequestOutputs = new List <eTimedBarsRequestOutputs>();
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrActualVolume);
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrTickVolume);
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrAskVolume);
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrBidVolume);
            TimedBarsRequestOutputs.Add(eTimedBarsRequestOutputs.tbrOpenInterest);
            int recurrenceСount = 10;

            // act
            while (recurrenceСount > 0)
            {
                m_TimedBarsRequest                              = fakeCQGCel.CreateTimedBarsRequest();
                m_TimedBarsRequest.Symbol                       = "h";
                m_TimedBarsRequest.IncludeEnd                   = false;
                m_TimedBarsRequest.RangeStart                   = startTime;
                m_TimedBarsRequest.RangeEnd                     = DateTime.Now;
                m_TimedBarsRequest.HistoricalPeriod             = eHistoricalPeriod.hpWeekly;
                m_TimedBarsRequest.TickFilter                   = eTickFilter.tfDefault;
                m_TimedBarsRequest.Continuation                 = eTimeSeriesContinuationType.tsctNoContinuation;
                m_TimedBarsRequest.EqualizeCloses               = true;
                m_TimedBarsRequest.DaysBeforeExpiration         = 0;
                m_TimedBarsRequest.UpdatesEnabled               = false;
                m_TimedBarsRequest.IgnoreEventsOnHistoricalBars = false;
                m_TimedBarsRequest.SessionsFilter               = 0;
                m_TimedBarsRequest.SessionFlags                 = eSessionFlag.sfUndefined;
                m_TimedBarsRequest.ExcludeAllOutputs();
                foreach (eTimedBarsRequestOutputs selectedOutput in TimedBarsRequestOutputs)
                {
                    m_TimedBarsRequest.IncludeOutput(selectedOutput, true);
                }
                CQGTimedBars TimedBars = fakeCQGCel.RequestTimedBars(m_TimedBarsRequest);
                CQGTimedBars = fakeCQGCel.AllTimedBars.get_ItemById(TimedBars.Id);

                // assert
                Assert.IsNotNull(CQGTimedBars);
                Assert.AreEqual(25, CQGTimedBars.Count);
                recurrenceСount--;
            }
        }
Example #2
0
        public static void StoreBarData(CQGTimedBars mCurTimedBars, CQGError cqgError, string userName)
        {
            //try
            //{g

            if (cqgError != null && cqgError.Code != 0)
            {
                FinishCollectingSymbol(mCurTimedBars.Request.Symbol, false, 0, "Expired! Error code: " + cqgError.Code + ". Description:" + cqgError.Description);
            }
            else
            {
                var str5 = mCurTimedBars.Request.Symbol.Trim();
                var str  = str5.Split('.');
                str5 = str[str.Length - 1];
                var tableName = "B_" + str5 + "_" + GetTableType(_historicalPeriod);


                var realyInsertedRows = 0;

                if (mCurTimedBars.Status == eRequestStatus.rsSuccess)
                {
                    ClientDatabaseManager.DeleteLastBar("B_" + str5 + "_" + GetTableType(_historicalPeriod));

                    var lastExisting3000BarData = ClientDatabaseManager.GetLast3000BarData(tableName);

                    if (mCurTimedBars.Count != 0)
                    {
                        for (int i = mCurTimedBars.Count - 1; i >= 0; i--)
                        {
                            if (!lastExisting3000BarData.Contains(mCurTimedBars[i].Timestamp))
                            {
                                AddBar(mCurTimedBars[i], mCurTimedBars.Request.Symbol, DateTime.Now, GetTableType(_historicalPeriod), userName);
                                realyInsertedRows++;
                            }
                        }
                    }
                    ClientDatabaseManager.CommitQueueBar();
                }
                //var rowsCount = mCurTimedBars.Count;//DatabaseManager.GetRowsCount("B_" + str5 + "_" + GetTableType(_historicalPeriod)) - beforeRowsCount
                FinishCollectingSymbol(mCurTimedBars.Request.Symbol, true, realyInsertedRows, "");
            }



            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("BarsAdd."+ex.Message);
            //}
        }
Example #3
0
        static void _cel_TimedBarsResolved(CQGTimedBars cqgTimedBars, CQGError cqgError)
        {
            ChangeTimeoutState(false, false);
            if (!IsStarted)
            {
                return;
            }
            if (_isStoped)
            {
                return;
            }

            var symbol = cqgTimedBars.Request.Symbol;

            StoreBarData(cqgTimedBars, cqgError, _userName);
        }
		private void SessionOnTimedBarsAdded(CQGTimedBars cqgTimedBars)
		{
			
		}
		private void SessionOnTimedBarsUpdated(CQGTimedBars cqgTimedBars, int index)
		{
			
		}
Example #6
0
        public void BarsAdd(CQGTimedBars mCurTimedBars, CQGError cqgError, string userName)
        {
            if (_shouldStop) return;
            try
            {
                _logger.LogAdd("Bars data resolved for symbol:" + mCurTimedBars.Request.Symbol, Category.Information, true);

                var ss = _aSymbolStates[mCurTimedBars.Request.Symbol];
                ss.IsCollected = true;

                if (cqgError != null && cqgError.Code != 0)
                {
                    ss.IsSuccess = false;
                }
                else
                {
                    if (mCurTimedBars.Status == eRequestStatus.rsSuccess)
                    {
                        DateTime runDateTime = DateTime.Now;
                        if (mCurTimedBars.Count != 0)
                        {
                            for (int i = mCurTimedBars.Count - 1; i >= 0; i--)
                            {
                                if (_shouldStop) break;
                                AddBar(mCurTimedBars[i], mCurTimedBars.Request.Symbol, runDateTime, _aTableType, userName);
                            }
                        }
                        DatabaseManager.CommitQueueBar();
                    }
                    ss.IsSuccess = true;
                }

                _aSymbolStates[mCurTimedBars.Request.Symbol] = ss;
                OnSymbolCollectEnd(mCurTimedBars.Request.Symbol, ss.IsSuccess, _aTableType);//TODO CHnaged this _aTableType

                if (SymbolsCollected == _aSymbolStates.Count)
                {
                    OnFinished();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                _logger.LogAdd("BarsAdd. " + ex, Category.Error);
            }
        }
        public static void BarsAdd(CQGTimedBars mCurTimedBars, CQGError cqgError, string userName)
        {
            try
            {

                if (cqgError != null && cqgError.Code != 0)
                {
                    FinishCollectingSymbol(mCurTimedBars.Request.Symbol, false);
                }
                else
                {
                    var str5 = mCurTimedBars.Request.Symbol.Trim();
                var str = str5.Split('.');
                str5 = str[str.Length - 1];

                    if (mCurTimedBars.Status == eRequestStatus.rsSuccess)
                    {
                        DatabaseManager.DeleteLastBar("B_" + str5 + "_" + GetTableType(_historicalPeriod));

                        DateTime runDateTime = DateTime.Now;
                        if (mCurTimedBars.Count != 0)
                        {
                            for (int i = mCurTimedBars.Count - 1; i >= 0; i--)
                            {
                                AddBar(mCurTimedBars[i], mCurTimedBars.Request.Symbol, runDateTime, GetTableType(_historicalPeriod), userName);
                            }
                        }
                        DatabaseManager.CommitQueueBar();
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static void _cel_TimedBarsResolved(CQGTimedBars cqgTimedBars, CQGError cqgError)
        {
            ChangeTimeoutState(false, false);

            if (_isStoped) return;

            var symbol = cqgTimedBars.Request.Symbol;

            BarsAdd(cqgTimedBars, cqgError, _userName);
            FinishCollectingSymbol(symbol, true);
        }
 private void SessionOnTimedBarsAdded(CQGTimedBars cqgTimedBars)
 {
 }
 private void SessionOnTimedBarsUpdated(CQGTimedBars cqgTimedBars, int index)
 {
 }
        public static void StoreBarData(CQGTimedBars mCurTimedBars, CQGError cqgError, string userName)
        {
            //try
            //{g

            if (cqgError != null && cqgError.Code != 0)
            {
                FinishCollectingSymbol("B",mCurTimedBars.Request.Symbol, false, 0, "Expired! Error code: " + cqgError.Code + ". Description:" + cqgError.Description);
            }
            else
            {
                var str5 = mCurTimedBars.Request.Symbol.Trim();
                var str = str5.Split('.');
                str5 = str[str.Length - 1];
                var tableName = "B_" + str5 + "_" + GetTableType(_historicalPeriod);

                var realyInsertedRows = 0;

                if (mCurTimedBars.Status == eRequestStatus.rsSuccess)
                {
                    ClientDatabaseManager.DeleteLastBar("B_" + str5 + "_" + GetTableType(_historicalPeriod));

                    var lastExisting3000BarData = ClientDatabaseManager.GetLast3000BarData(tableName);

                    if (mCurTimedBars.Count != 0)
                    {
                        for (int i = mCurTimedBars.Count - 1; i >= 0; i--)
                        {
                            if (!lastExisting3000BarData.Contains(mCurTimedBars[i].Timestamp))
                            {
                                AddBar(mCurTimedBars[i], mCurTimedBars.Request.Symbol, DateTime.Now, GetTableType(_historicalPeriod), userName);
                                realyInsertedRows++;
                            }
                        }
                    }
                    ClientDatabaseManager.CommitQueueBar();

                }
                //var rowsCount = mCurTimedBars.Count;//DatabaseManager.GetRowsCount("B_" + str5 + "_" + GetTableType(_historicalPeriod)) - beforeRowsCount
                FinishCollectingSymbol("B",mCurTimedBars.Request.Symbol, true, realyInsertedRows, "");
            }

            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("BarsAdd."+ex.Message);
            //}
        }
        static void _cel_TimedBarsResolved(CQGTimedBars cqgTimedBars, CQGError cqgError)
        {
            ChangeTimeoutState(false, false);
            if (!IsStarted) return;
            if (_isStoped) return;

            var symbol = cqgTimedBars.Request.Symbol;
            StoreBarData(cqgTimedBars, cqgError, _userName);
        }
        public static void BarsAdd(CQGTimedBars mCurTimedBars, CQGError cqgError, string userName)
        {
            try
            {

                if (cqgError != null && cqgError.Code != 0)
                {

                }
                else
                {
                    if (mCurTimedBars.Status == eRequestStatus.rsSuccess)
                    {
                        DateTime runDateTime = DateTime.Now;
                        if (mCurTimedBars.Count != 0)
                        {
                            for (int i = mCurTimedBars.Count - 1; i >= 0; i--)
                            {
                                AddBar(mCurTimedBars[i], mCurTimedBars.Request.Symbol, runDateTime, GetTableType(_historicalPeriod), userName);
                            }
                        }
                        DataNetClientDataManager.CommitQueueBar();
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        static void _cel_TimedBarsResolved(CQGTimedBars cqgTimedBars, CQGError cqgError)
        {
            if (_isStoped) return;
            var symbol = cqgTimedBars.Request.Symbol;

            BarsAdd(cqgTimedBars, cqgError, _userName);
            FinishCollectingSymbol(symbol);
        }
Example #15
0
 void CEL_TimedBarsResolved(CQGTimedBars cqg_timed_bars, CQGError cqg_error)
 {
     _dataCollector.BarsAdd(cqg_timed_bars, cqg_error, _client.UserName);
 }