public async Task <List <Responses.Watcher> > GetUserWatchers(string userId = null, string currencyId = null, string indicatorId = null) { // Get user var user = await _mainDbContext.Users.FindAsync(userId); // Check if it exists if (user == null) { throw new NotFoundException(UserMessage.UserNotFound); } // Get user watchers var userWatchers = await _mainDbContext.Watchers.Where(WatcherExpression.Filter(userId, currencyId, indicatorId)).ToListAsync(); // Response var response = _mapper.Map <List <Responses.Watcher> >(userWatchers); // Return return(response); }
public static void BuildLines(List <Currency> currencies, List <Indicator> indicators, List <Watcher> watchers, List <Line> lines, DateTime time, int dependencyLevel, int stopAt) { // For each currency foreach (var currency in currencies) { // For each indicator of the given level foreach (var indicator in indicators.Where(x => x.DependencyLevel == dependencyLevel)) { // Get all watchers for this currency indicator pair var filteredWatchers = watchers.Where(WatcherExpression.Filter(null, currency.CurrencyId, indicator.IndicatorId).Compile()).ToList(); // Build value and averages var value = IndicatorBuilder.BuildValue(currency, indicator, lines); var averageBuy = BuildWeightedAverageBuy(filteredWatchers); var averageSell = BuildWeightedAverageSell(filteredWatchers); // Create line var line = new Line( time, indicator.UserId, currency.CurrencyId, indicator.IndicatorId, value, averageBuy, averageSell, currency.Price); // Add line lines.Add(line); } } // Do the same with the next level recursively if (dependencyLevel < stopAt) { BuildLines(currencies, indicators, watchers, lines, time, dependencyLevel + 1, stopAt); } }