コード例 #1
0
ファイル: StockService.cs プロジェクト: js910924/Teleport
        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}");
            }
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
 private void GiveStockInfoFromProxy(StockInfo stockInfo)
 {
     _stockProxy.GetStockInfo(stockInfo.Symbol)
     .Returns(Task.FromResult(stockInfo));
 }