Пример #1
0
        public void FillGapsByTicker(string ticker, DateTime startTime)
        {
            if (worker.CancellationPending)
            {
                return;
            }
            var ctrl = quoteControls[ticker];

            if (ctrl.Gaps == null)
            {
                return;
            }
            var gaps = ctrl.Gaps.ToList();

            if (gaps.Count == 0)
            {
                return;
            }

            UpdateCurrentTickerLabelSafe(ticker);

            FileGapActualizator.FillGapsByTickerFast(ticker, startTime, DateTime.Now, gaps,
                                                     ExecutablePath.ExecPath + TerminalEnvironment.QuoteCacheFolder,
                                                     worker, UpdateControlSafe);
        }
Пример #2
0
        public void TestLoadQuotesFromServerFast()
        {
            var gaps = FileGapActualizator.VerifyTickerHistory(Ticker, timeHistStart, quoteFolder, null, timeNow);

            FileGapActualizator.FillGapsByTickerFast(Ticker, timeHistStart, timeNow, gaps, quoteFolder, null,
                                                     (s, list) =>
            {
                Console.WriteLine("--------------");
                foreach (var gap in list)
                {
                    Console.WriteLine("Gap progress: {0}", gap);
                }
            });

            // закачка в целом успешна
            var clientCandles = AtomCandleStorage.Instance.GetAllMinuteCandles(Ticker);

            Assert.Greater(clientCandles.Count, 0, "TestLoadQuotesFromServerFast: client candles not loaded");

            var serverCandlesPacked = QuoteStorage.Instance.proxy.GetMinuteCandlesPacked(Ticker, timeHistStart, DateTime.Now);
            var serverCandles       = serverCandlesPacked.GetCandles();
            var lastServerTime      = serverCandles[serverCandles.Count - 1].timeOpen;
            var lastClientTime      = clientCandles[clientCandles.Count - 1].timeOpen;

            Assert.AreEqual(lastServerTime, lastClientTime, "TestLoadQuotesFromServerFast: last candle not loaded");

            // сравнить количество свечек на клиенте и на сервере

            /*var maxIndex = Math.Min(clientCandles.Count, serverCandles.Count);
             * for (var index = 0; index < maxIndex; index++)
             * {
             *  Assert.AreEqual(clientCandles[index].timeOpen, serverCandles[index].timeOpen, "TestLoadQuotesFromServerFast: candles not equal");
             * }
             * Assert.GreaterOrEqual(clientCandles.Count, serverCandles.Count, "TestLoadQuotesFromServerFast: client candles lost");*/

            // убедиться в том, что дырок больше нет
            var gapsNew = FileGapActualizator.VerifyTickerHistory(Ticker, timeHistStart, quoteFolder, null, timeNow);
            var gapsNewThatIsNotOnServer = gapsNew.Count(g => !serverGaps.Any(sg => sg.AreEqual(g.start, g.end)));

            Assert.AreEqual(0, gapsNewThatIsNotOnServer, "TestLoadQuotesFromServerFast: gaps still found");

            // свечи упорядочены по возрастанию, дубликатов нет
            var hasDouble = false;

            for (var i = 1; i < clientCandles.Count; i++)
            {
                if (clientCandles[i].timeOpen <= clientCandles[i - 1].timeOpen)
                {
                    hasDouble = true;
                    break;
                }
            }
            Assert.AreEqual(false, hasDouble, "TestLoadQuotesFromServerFast: double candles found");

            // повторно подкачать гэпы - убедиться, что новых обращений к серверу не было
            FileGapActualizator.FillGapsByTickerFast(Ticker, timeHistStart, timeNow, gapsNew, quoteFolder, null,
                                                     (s, list) =>
            {
                Assert.Fail("VerifyHistory: redundant server call");
            });
        }