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); }
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); }
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>()); } }
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); } }