public DataViewModel Calculate(int begin, int end) { var ticks = futuresService.GetTicks(begin, end); double buyQty = 0; double sellQty = 0; int itemBuyQty = ticks.Where(t => t.type == 1).Sum(t => t.qty); int itemSellQty = ticks.Where(t => t.type == -1).Sum(t => t.qty); buyQty += itemBuyQty; sellQty += itemSellQty; var result = new string[] { Convert.ToInt32(Math.Ceiling(buyQty)).ToString(), Convert.ToInt32(Math.Ceiling(sellQty)).ToString() }; var data = new DataViewModel { indicator = nameof(Powers), text = String.Join(",", result), val = Math.Ceiling(buyQty - sellQty).ToString() }; return(data); }
public DataViewModel Calculate(int begin, int end) { var ticks = futuresService.GetTicks(begin, end); var result = ticks.GroupBy(t => t.price, t => t.qty, (price, qty) => new { Price = price, Qty = qty.Sum() }); double totalPrices = result.Sum(r => r.Price * r.Qty); int totalQty = result.Sum(r => r.Qty); var avg = Math.Round((totalPrices / totalQty), 2); var data = new DataViewModel { indicator = nameof(Prices), text = avg.ToString(), val = avg.ToString() }; return(data); }