private async Task GetRealTimeStockPosition(StockPosition position) { try { var stockInfo = await _stockInfoRepo.GetStockInfo(position.Ticker); if (stockInfo.Symbol != position.Ticker) { stockInfo = await _stockProxy.GetStockInfo(position.Ticker); await _stockInfoRepo.UpsertStockInfo(stockInfo); } var currentValue = stockInfo.Price * position.Shares; var gain = currentValue - position.Cost; position.CurrentPrice = stockInfo.Price; position.CurrentValue = currentValue; position.PercentageOfChange = Math.Round(stockInfo.PercentageOfChange, 4); position.Change = stockInfo.Change; position.Gain = gain; position.PercentageOfGain = Math.Round(gain / position.Cost, 4); } catch (Exception e) { throw new Exception($"GetRealTimeStockPosition Fail | stock symbol = {position.Ticker}, exception = {e}"); } }
public async Task Execute(IJobExecutionContext context) { var stockInfos = await _stockInfoRepo.GetAllStockInfo(); foreach (var stockInfo in stockInfos) { var info = await _stockProxy.GetStockInfo(stockInfo.Symbol); await _stockInfoRepo.UpsertStockInfo(info); } }
private void GiveStockInfoFromProxy(StockInfo stockInfo) { _stockProxy.GetStockInfo(stockInfo.Symbol) .Returns(Task.FromResult(stockInfo)); }