private static async Task UpdateLastPriceRate(decimal lastPrice, LastPriceRate lastPriceRates) { lastPriceRates.LastPrices.Enqueue(lastPrice); if (lastPriceRates.LastPrices.Count > Intervals[Intervals.Length - 1]) { lastPriceRates.LastPrices.Dequeue(); } lastPriceRates.LastPriceRates = await GetPriceRates(lastPriceRates); }
private static async Task <List <string> > GetPriceRates(LastPriceRate lastPriceRates) { List <string> results = new List <string>(); await Task.Run(() => { foreach (int interval in Intervals) { if (lastPriceRates.LastPrices.Count >= interval) { decimal total = decimal.Zero; decimal i = decimal.Zero; foreach (decimal item in lastPriceRates.LastPrices) { if (i < interval) { total += item; i++; } else { break; } } decimal average = total / interval; if (average != decimal.Zero) { //decimal difference = (lastPriceRates.LastPrice - average) / average; //results.Add(difference.ToString("P", CultureInfo.InvariantCulture)); //decimal difference = (lastPriceRates.LastPrice - average) / average; results.Add(average.ToString("0.########")); } else { results.Add("0.0%"); } } else { break; } } }); return(results); }