Exemple #1
0
        public void TestPackedCandleStream()
        {
            var stream =
                new PackedCandleStream(
                    srcCandles.Select(
                        c =>
                        new CandleDataPacked
            {
                timeOpen = c.timeOpen,
                open     = c.open,
                HLC      = c.GetHlcOffset16(VersePointValue),
                close    = c.close
            }).ToList(), true);
            var parsedCandles = stream.GetCandles().Select(c =>
            {
                var candle = new CandleData {
                    timeOpen = c.timeOpen, open = c.open, close = c.close
                };
                candle.MakeHlcFromOffset16(c.HLC, VersePointValue);
                return(candle);
            }).ToList();

            for (var candleIndex = 0; candleIndex < srcCandles.Count; candleIndex++)
            {
                var candle       = srcCandles[candleIndex];
                var parsedCandle = parsedCandles[candleIndex];
                Assert.AreEqual(candle.high, parsedCandle.high, 0.000001, "TestPackedCandleStream: ParseLine error (high)");
                Assert.AreEqual(candle.low, parsedCandle.low, 0.000001, "TestPackedCandleStream: ParseLine error (low)");
                Assert.AreEqual(candle.close, parsedCandle.close, 0.000001, "TestPackedCandleStream: ParseLine error (close)");
            }
        }
        public static Mock <IQuoteStorage> MakeMoq(Dictionary <string, List <CandleData> > candlesM1)
        {
            var moq = new Mock <IQuoteStorage>();

            moq.Setup(s => s.GetTickersHistoryStarts()).Returns(
                () => candlesM1.ToDictionary(c => c.Key, c => new DateSpan(c.Value[0].timeOpen,
                                                                           c.Value[c.Value.Count - 1].timeOpen)));

            moq.Setup(s => s.GetMinuteCandlesPacked(It.IsAny <string>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()))
            .Returns((string ticker, DateTime start, DateTime end) =>
            {
                if (!candlesM1.ContainsKey(ticker))
                {
                    return(new PackedCandleStream(new List <CandleDataPacked>(), false));
                }
                var candles = candlesM1[ticker].Where(c => c.timeOpen >= start && c.timeOpen <= end).Select(c => new CandleDataPacked
                {
                    open     = c.open,
                    timeOpen = c.timeOpen
                }).ToList();

                var stream = new PackedCandleStream(candles, candles.Count > 100);
                return(stream);
            });

            moq.Setup(s => s.GetMinuteCandlesPackedFast(It.IsAny <string>(), It.IsAny <List <Cortege2 <DateTime, DateTime> > >()))
            .Returns((
                         string symbol, List <Cortege2 <DateTime, DateTime> > intervals) =>
            {
                if (!candlesM1.ContainsKey(symbol))
                {
                    return(new PackedCandleStream(new List <CandleDataPacked>(), false));
                }
                var candles = new List <CandleDataPacked>();
                foreach (var interval in intervals)
                {
                    candles.AddRange(
                        candlesM1[symbol].Where(c => c.timeOpen >= interval.a && c.timeOpen <= interval.b)
                        .Select(c => new CandleDataPacked
                    {
                        open     = c.open,
                        timeOpen = c.timeOpen
                    }));
                }
                var stream = new PackedCandleStream(candles, candles.Count > 100);
                return(stream);
            });

            return(moq);
        }