コード例 #1
0
        public void SetTotalValue()
        {
            IStockValues values = new StockValues();

            values.SetTotalValue(new DateTime(2009, 3, 23), 10.0);
            Assert.AreEqual(values.GetAllDate().Count, 1);

            values.SetTotalValue(new DateTime(2009, 3, 24), 12.0);
            Assert.AreEqual(values.GetAllDate().Count, 2);

            values.SetTotalValue(new DateTime(2009, 3, 25), -1); // invalid
            Assert.AreEqual(values.GetAllDate().Count, 2);
        }
コード例 #2
0
        public void GetTotalValue()
        {
            IStockValues values = new StockValues();

            DateTime dt = new DateTime(2009, 3, 23);

            values.SetTotalValue(dt, 10.0);

            double val = values.GetTotalValue(dt);

            Assert.AreEqual(val, 10.0);

            val = values.GetTotalValue(new DateTime(1980, 1, 1));
            Assert.IsTrue(val < 0);
        }
コード例 #3
0
        public List <Stock> ReadStockFile()
        {
            if (File.Exists(@StockDir))
            {
                List <Stock> stockItems = File.ReadAllLines(@StockDir)
                                          .Select(v => StockValues.ParseToObject(v))
                                          .ToList();
                return(stockItems);
            }

            else
            {
                EmptyFile(@StockDir);
                return(new List <Stock>());
            }
        }
コード例 #4
0
        protected override async Task Invoke()
        {
            var strategy = (PercentStrategy)Strategy;

            var value         = CurrentStockData.CurrentPrice;
            var computedValue = Convert.ToDecimal(value) * strategy.Percent;
            var roofValues    = StockValues.Where(x => x.CurrentPrice >= computedValue).ToList();

            if (roofValues.Any())
            {
                roofValue = roofValues.Min(x => x.CurrentPrice);
            }
            if (BuyingPrice == 0 && roofValue > 0)
            {
                await Buy(value);
            }

            var computedBuyingPrice = Convert.ToDecimal(BuyingPrice) * strategy.Percent;

            if (BuyingPrice != 0 && computedBuyingPrice <= value && Profitable(value))
            {
                await Sell(value);
            }
        }