private async Task <bool> UpdatePriceInStorageAsync(DateTime currentDate) { IStockPriceHistory item = await _memoryDbOperations.GetStockPriceHistoryAsync(_baseData.Country, _stockId, currentDate).ConfigureAwait(false); if (item == null) { return(false); } ICurrentPrice value = new CurrentPriceItem(item.ClosePrice, item.TradeDateTime, item.HighPrice, item.LowPrice); _storage.AddOrUpdateItem(_baseData.Country, _stockId, value); return(true); }
protected override async Task RunInternalAsync(CancellationToken token) { WriteToHeartBeatLog(); if (token.IsCancellationRequested) { return; } IReadOnlyList <IStock> _stockList = await DatabaseOperations.GetStocksAsync(Country).ConfigureAwait(false); if (_stockList == null || _stockList.Count == 0 || token.IsCancellationRequested) { return; } IReadOnlyList <IStockQuoteFromDataSource> priceData = await GetStockPricesFromDataSourceAsync(_stockList).ConfigureAwait(false); int successCount = 0; foreach (IStockQuoteFromDataSource data in priceData) { if (data.IsValid) { ICurrentPrice currentPriceItem = new CurrentPriceItem(data.ClosePrice, data.TradeDateTime, data.HighPrice, data.LowPrice); CountryKind country = data.Country.ConvertToTT2Country(); BaseData.CurrentPriceStorage.AddOrUpdateItem(country, data.StockId, currentPriceItem); successCount++; } } WriteToWorkerLog($"Getting back {successCount} of {_stockList.Count} stocks from data source."); }