public override async Task <object> Handle(Query request, CancellationToken cancellationToken) { var alerts = await _alertsStorage.GetAlerts(request.UserId); var list = new List <object>(); foreach (var a in alerts.OrderByDescending(a => a.PricePoints.Any(p => _container.HasTriggered(p))).ThenBy(a => a.Ticker)) { if (a.PricePoints.Count == 0) { continue; } var price = await _stock.GetPrice(a.Ticker); list.Add(new { currentPrice = price.Success.Amount, ticker = a.State.Ticker.Value, points = a.State.PricePoints.Select(pp => new { pp.Id, pp.Value, pp.Description, triggered = _container.HasTriggered(pp) }), }); } return(list); }
public async Task Handle(NoteCreated e, CancellationToken cancellationToken) { var n = await _storage.GetNote(e.UserId, e.AggregateId); if (n == null) { return; } var age = System.DateTimeOffset.UtcNow.Subtract(e.When).TotalDays; if (age > 2) { return; } var d = await _stocks.GetAdvancedStats(n.State.RelatedToTicker); var p = await _stocks.GetPrice(n.State.RelatedToTicker); if (d.IsOk && p.IsOk) { n.Enrich(p.Success, d.Success); await _storage.Save(n, n.State.UserId); } }
public override async Task <object> Handle(Query request, CancellationToken cancellationToken) { var option = await _storage.GetOwnedOption(request.Id, request.UserId); var price = await _stockService.GetPrice(option.State.Ticker); return(price.IsOk switch { true => new OwnedOptionView(option, price.Success.Amount), false => new OwnedOptionView(option) });
public async Task <object> Handle(Query request, CancellationToken cancellationToken) { var profile = _stocksService2.GetCompanyProfile(request.Ticker); var advanced = _stocksService2.GetAdvancedStats(request.Ticker); var price = _stocksService2.GetPrice(request.Ticker); await Task.WhenAll(profile, advanced, price); return(new StockDetailsView { Ticker = request.Ticker, Price = price.Result.Success.Amount, Profile = profile.Result.Success, Stats = advanced.Result.Success }); }
public async Task <object> Handle(Query request, CancellationToken cancellationToken) { var profile = _stocksService2.GetCompanyProfile(request.Ticker); var advanced = _stocksService2.GetAdvancedStats(request.Ticker); var price = _stocksService2.GetPrice(request.Ticker); var data = _stocksService.GetHistoricalDataAsync(request.Ticker); var metrics = _stocksService.GetKeyMetrics(request.Ticker); await Task.WhenAll(profile, advanced, price, data, metrics); return(Mapper.MapStockDetail( request.Ticker, price.Result.Amount, profile.Result, advanced.Result, data.Result, metrics.Result)); }
public async Task <OptionDetailsViewModel> Handle(Query request, CancellationToken cancellationToken) { var price = await _stocks.GetPrice(request.Ticker); if (!price.IsOk || price.Success.NotFound) { return(null); } var dates = await _options.GetOptions(request.Ticker); var upToFour = dates.Take(4); var options = new List <OptionDetail>(); foreach (var d in upToFour) { var details = await _options.GetOptionDetails(request.Ticker, d); options.AddRange(details); } return(MapOptionDetails(price.Success.Amount, options)); }
public override async Task <object> Handle(Query request, CancellationToken cancellationToken) { var stocks = await _storage.GetStocks(request.UserId); var owned = stocks.Where(s => s.State.Owned > 0); var options = await _storage.GetOwnedOptions(request.UserId); var openOptions = options .Where(o => o.State.NumberOfContracts != 0 && o.State.DaysUntilExpiration > -5) .OrderBy(o => o.State.Expiration); var prices = owned.Select(o => o.Ticker).Union(openOptions.Select(o => o.Ticker)) .Distinct() .ToDictionary(s => s, async s => await _stocksService.GetPrice(s)); var obj = new { owned = owned.Select(o => Mapper.ToOwnedView(o, prices[o.Ticker].Result)), openOptions = openOptions.Select(o => Mapper.ToOptionView(o, prices[o.Ticker].Result)) }; return(obj); }