public async Task <List <Responses.Watcher> > GetAllWatchers(string userId = null, string currencyId = null, string indicatorId = null) { // Get user var user = await _userRepository.GetSingle(userId); // Check if it exists if (user == null) { throw new NotFoundException(UserMessage.UserNotFound); } // Get all watchers var userWatchers = await _watcherRepository.GetAll(WatcherExpression.WatcherFilter(userId, currencyId, indicatorId)); // Get all default watchers var defaultWatchers = await _watcherRepository.GetAll(WatcherExpression.DefaultWatcher(currencyId, indicatorId)); // Build with defaults userWatchers = WatcherBuilder.BuildWatchersWithDefaults(userWatchers, defaultWatchers); // 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 <DataPoint> lines, int dependencyLevel, int stopAt) { foreach (var currency in currencies) { foreach (var indicator in indicators) { if (indicator.DependencyLevel == dependencyLevel) // We set the consecutive ones { // Get latest line for this currency indicator pair var line = lines.FirstOrDefault(LineExpression.Line(lines[0].Time, currency.CurrencyId, indicator.IndicatorId).Compile()); // Get all watchers for this currency indicator pair var filteredWatchers = watchers.Where(WatcherExpression.WatcherFilter(null, currency.CurrencyId, indicator.IndicatorId).Compile()).ToList(); // Build var value = IndicatorBuilder.BuildValue(currency, indicator, lines); var averageBuy = IndicatorBuilder.BuildAverageBuy(filteredWatchers); var averageSell = IndicatorBuilder.BuildAverageSell(filteredWatchers); // Set line?.Set(value, averageBuy, averageSell); } } } // Do the same with the next level recursively if (dependencyLevel < stopAt) { BuildLines(currencies, indicators, watchers, lines, dependencyLevel + 1, stopAt); } }
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); } // Filter user watchers var userWatchers = await _mainDbContext.Watchers.Where(WatcherExpression.WatcherFilter(userId, currencyId, indicatorId)).ToListAsync(); // Get all default watchers var defaultWatchers = await _mainDbContext.Watchers.Where(WatcherExpression.DefaultWatcher(currencyId, indicatorId)).ToListAsync(); // Build with defaults userWatchers = WatcherBuilder.BuildWatchersWithDefaults(userWatchers, defaultWatchers); // Response var response = _mapper.Map <List <Responses.Watcher> >(userWatchers); // Return return(response); }
public static List <DataPoint> BuildLines(List <Currency> currencies, List <Indicator> indicators, List <Watcher> watchers) { var lines = new List <DataPoint>(); var time = DateTime.Now; var stopAt = indicators.Count > 0 ? indicators.Max(x => x.DependencyLevel) : 0; // We create the lines in the order that is given. We build the first level (DependencyLevel = 0) for now foreach (var currency in currencies) { foreach (var indicator in indicators) { decimal?value = null; decimal?averageBuy = null; decimal?averageSell = null; if (indicator.DependencyLevel == 0) { // Get all watchers for this currency indicator pair var filteredWatchers = watchers.Where(WatcherExpression.WatcherFilter(null, currency.CurrencyId, indicator.IndicatorId).Compile()).ToList(); // Build value = IndicatorBuilder.BuildValue(currency, indicator); averageBuy = IndicatorBuilder.BuildAverageBuy(filteredWatchers); averageSell = IndicatorBuilder.BuildAverageSell(filteredWatchers); } // Add var dataPoint = new DataPoint(currency.CurrencyId, indicator.IndicatorId, indicator.IndicatorType, indicator.UserId, value, averageBuy, averageSell, true, time); lines.Add(dataPoint); } } // Now we build the deper levels if (stopAt > 0) { BuildLines(currencies, indicators, watchers, lines, 1, stopAt); } // Return return(lines); }