public void TwoPrices()
        {
            var                    priceReader = new InMemoryPriceReader();
            var                    reader      = new CandleStickReader(timeframe: 15, PriceReader: priceReader);
            int                    count       = 0;
            CandleStickItme        itme        = null;
            List <CandleStickItme> item        = new List <CandleStickItme>();

            var dt1 = new DateTime(2017, 5, 5, 10, 5, 0);
            var dt2 = new DateTime(2017, 5, 5, 10, 10, 0);


            priceReader.AddSeedPrice(dt1, 12m, 0, 0);
            priceReader.AddSeedPrice(dt2, 14m, 0, 0);


            reader.NewCandleStick += (sender, e) =>
            {
                count++;
                itme = e.CandleStick;
            };

            reader.Start();

            Assert.Equal(1, count);
            Assert.Equal(12m, itme.Open);
            Assert.Equal(12m, itme.Low);
            Assert.Equal(14m, itme.High);
            Assert.Equal(14m, itme.Close);
            var dt0 = new DateTime(2017, 5, 5, 10, 0, 0);

            //Assert.Equal(dt0, itme.Date);
            Assert.Equal(CandleStickColor.Green, itme.Color);
        }
        public void TwoPrices()
        {
            // arrange
            var             p     = new InMemoryPriceReader();
            var             c     = new CandleStickReader(timeframe: 15, priceReader: p);
            int             count = 0;
            CandleStickItem item  = null;
            var             dt1   = new DateTime(2017, 5, 5, 10, 1, 0);
            var             dt2   = new DateTime(2017, 5, 5, 10, 2, 0);

            p.AddSeedPrice(dt1, 12m, 0m, 0m);
            p.AddSeedPrice(dt2, 14m, 0m, 0m);

            c.NewCandleStick += (sender, e) =>
            {
                count++;
                item = e.CandleStick;
            };

            // a
            c.Start();

            // a
            Assert.Equal(1, count);
            Assert.Equal(12m, item.Low);
            Assert.Equal(12m, item.Open);
            Assert.Equal(14m, item.High);
            Assert.Equal(14m, item.Close);
            Assert.Equal(CandleStickColor.Green,
                         item.Color);
        }
Example #3
0
        public void ThreePrices()
        {
            var     reader       = new InMemoryPriceReader();
            decimal price        = 0m;
            int     count        = 0;
            bool    foundStopper = false;

            reader.AddSeedPrice(last: 15.0m);
            reader.AddSeedPrice(last: 16.0m);
            reader.AddSeedPrice(last: 14.0m);

            reader.NewPrice += (sender, e) =>
            {
                if (e.NewPrice != null)
                {
                    price = e.NewPrice.Last;
                    count++;
                }
                else
                {
                    foundStopper = true;
                }
            };


            reader.Start();

            Assert.Equal(3, count);
            Assert.True(foundStopper);
        }
        public void ThreeCandleSticks()
        {
            // arrange
            var p     = new InMemoryPriceReader();
            var c     = new CandleStickReader(timeframe: 15, priceReader: p);
            int count = 0;
            List <CandleStickItem> items = new List <CandleStickItem>();
            var dt1 = new DateTime(2017, 5, 5, 10, 5, 0);
            var dt2 = new DateTime(2017, 5, 5, 10, 10, 0);
            var dt3 = new DateTime(2017, 5, 5, 10, 15, 0);
            var dt4 = new DateTime(2017, 5, 5, 10, 20, 0);
            var dt5 = new DateTime(2017, 5, 5, 10, 40, 0);
            var dt6 = new DateTime(2017, 5, 5, 10, 41, 0);
            var dt7 = new DateTime(2017, 5, 5, 10, 42, 0);

            p.AddSeedPrice(dt1, 12m, 0m, 0m);
            p.AddSeedPrice(dt2, 14m, 0m, 0m);
            p.AddSeedPrice(dt3, 16m, 0m, 0m);
            p.AddSeedPrice(dt4, 15m, 0m, 0m);
            p.AddSeedPrice(dt5, 20m, 0m, 0m);
            p.AddSeedPrice(dt6, 23m, 0m, 0m);
            p.AddSeedPrice(dt7, 22m, 0m, 0m);

            c.NewCandleStick += (sender, e) =>
            {
                count++;
                items.Add(e.CandleStick);
            };

            // a
            c.Start();

            // a
            Assert.Equal(3, count);
            Assert.Equal(12m, items[0].Low);
            Assert.Equal(12m, items[0].Open);
            Assert.Equal(14m, items[0].High);
            Assert.Equal(14m, items[0].Close);

            Assert.Equal(16m, items[1].Open);
            Assert.Equal(15m, items[1].Low);
            Assert.Equal(16m, items[1].High);
            Assert.Equal(15m, items[1].Close);

            Assert.Equal(20m, items[2].Open);
            Assert.Equal(20m, items[2].Low);
            Assert.Equal(23m, items[2].High);
            Assert.Equal(22m, items[2].Close);

            Assert.Equal(new DateTime(2017, 5, 5, 10, 0, 0), items[0].Date);
            Assert.Equal(new DateTime(2017, 5, 5, 10, 15, 0), items[1].Date);
            Assert.Equal(new DateTime(2017, 5, 5, 10, 30, 0), items[2].Date);
        }
        public void NoPrice_NoCandleStick()
        {
            // arrange
            var p     = new InMemoryPriceReader();
            var c     = new CandleStickReader(timeframe: 15, priceReader: p);
            int count = 0;

            c.NewCandleStick += (sender, e) => {
                count++;
            };
            c.Start();

            Assert.Equal(0, count);
        }
        public void NoPrice()
        {
            var priceReader = new InMemoryPriceReader();
            var reader      = new CandleStickReader(timeframe: 5, PriceReader: priceReader);
            int count       = 0;

            reader.NewCandleStick += (sender, e) =>
            {
                count++;
            };

            reader.Start();

            Assert.Equal(0, count);
        }
        public void NoSeedPrice_GetOnlyNullNewPriceItem()
        {
            var       reader = new InMemoryPriceReader();
            PriceItem price  = null;
            int       count  = 0;

            reader.NewPrice += (sender, e) => {
                price = e.NewPrice;
                count++;
            };

            reader.Start();

            Assert.Equal(1, count);
            Assert.Null(price);
        }
        public void SinglePrice()
        {
            var     reader = new InMemoryPriceReader();
            decimal price  = 0m;

            reader.AddSeedPrice(last: 15.0m);
            reader.NewPrice += (sender, e) => {
                if (e.NewPrice != null)
                {
                    price = e.NewPrice.Last;
                }
            };

            reader.Start();

            Assert.Equal(15.0m, price);
        }
Example #9
0
        public void NoSeedPrice()
        {
            var reader = new InMemoryPriceReader();

            decimal price = 0m;
            int     count = 0;

            reader.NewPrice += (sender, e) =>
            {
                if (e.NewPrice != null)
                {
                    price = e.NewPrice.Last;
                    count++;
                }
            };

            reader.Start();

            Assert.Equal(0, count);
            Assert.Equal(0m, price);
        }
        public void TwoCandlestick()
        {
            var priceReader = new InMemoryPriceReader();
            var reader      = new CandleStickReader(timeframe: 15, PriceReader: priceReader);
            int count       = 0;
            //CandleStickItme itme = null;
            List <CandleStickItme> items = new List <CandleStickItme>();

            var dt1 = new DateTime(2017, 5, 5, 10, 5, 0);
            var dt2 = new DateTime(2017, 5, 5, 10, 10, 0);
            var dt3 = new DateTime(2017, 5, 5, 10, 15, 0);
            var dt4 = new DateTime(2017, 5, 5, 10, 20, 0);

            priceReader.AddSeedPrice(dt1, 12m, 0, 0);
            priceReader.AddSeedPrice(dt2, 14m, 0, 0);
            priceReader.AddSeedPrice(dt3, 16m, 0, 0);
            priceReader.AddSeedPrice(dt4, 15m, 0, 0);

            reader.NewCandleStick += (sender, e) =>
            {
                count++;
                items.Add(e.CandleStick);
            };

            reader.Start();

            Assert.Equal(2, count);
            Assert.Equal(12m, items[0].Low);
            Assert.Equal(12m, items[0].Open);
            Assert.Equal(14m, items[0].High);
            Assert.Equal(14m, items[0].Close);

            Assert.Equal(16m, items[1].Open);
            Assert.Equal(15m, items[1].Low);
            Assert.Equal(16m, items[1].High);
            Assert.Equal(15m, items[1].Close);

            Assert.Equal(new DateTime(2017, 5, 5, 10, 0, 0), items[0].Date);
            Assert.Equal(new DateTime(2017, 5, 5, 10, 15, 0), items[1].Date);
        }
        public void SinglePrice_OneCandleStick()
        {
            // arrange
            var             p     = new InMemoryPriceReader();
            var             c     = new CandleStickReader(timeframe: 15, priceReader: p);
            int             count = 0;
            CandleStickItem item  = null;

            p.AddSeedPrice(12m);
            c.NewCandleStick += (sender, e) => {
                count++;
                item = e.CandleStick;
            };

            c.Start();

            Assert.Equal(1, count);
            Assert.Equal(12m, item.Open);
            Assert.Equal(12m, item.High);
            Assert.Equal(12m, item.Close);
            Assert.Equal(12m, item.Low);
            Assert.Equal(CandleStickColor.Green, item.Color);
        }
        public void ThreePrices()
        {
            var     reader = new InMemoryPriceReader();
            decimal price  = 0m;
            int     count  = 0;

            reader.AddSeedPrice(last: 15.0m);
            reader.AddSeedPrice(last: 16.0m);
            reader.AddSeedPrice(last: 14.0m);

            reader.NewPrice += (sender, e) => {
                if (e.NewPrice != null)
                {
                    price = e.NewPrice.Last;
                    count++;
                }
            };

            reader.Start();

            Assert.Equal(3, count);
            Assert.Equal(14.0m, price);
        }
        public void SinglePrice()
        {
            var             priceReader = new InMemoryPriceReader();
            var             reader      = new CandleStickReader(timeframe: 5, PriceReader: priceReader);
            int             count       = 0;
            CandleStickItme itme        = null;

            priceReader.AddSeedPrice(12m);

            reader.NewCandleStick += (sender, e) =>
            {
                count++;
                itme = e.CandleStick;
            };

            reader.Start();

            Assert.Equal(1, count);
            Assert.Equal(12m, itme.Open);
            Assert.Equal(12m, itme.High);
            Assert.Equal(12m, itme.Close);
            Assert.Equal(12m, itme.Low);
            Assert.Equal(CandleStickColor.Green, itme.Color);
        }