コード例 #1
0
        //Cannot use Task<PartialViewResult> on child action
        //https://justsimplycode.com/2016/09/04/child-action-in-mvc-5-does-not-support-async/
        public async Task <PartialViewResult> TrendingStocks()
        {
            var model = await _investagramsApiService.GetTrendingStocks();

            var latestStockData = _stockService.GetLatestStockHistory();


            var viewModel = model.Select(x =>
            {
                var stock = latestStockData.ContainsKey(x.Stock.StockCode) ? latestStockData[x.Stock.StockCode] : null;

                return(new TrendingStockViewModel
                {
                    StockCode = x.Stock.StockCode,
                    Last = stock?.Last ?? 0,
                    Open = stock?.Open ?? 0,
                    Trades = stock?.Trades ?? 0
                });
            }).ToList();


            return(PartialView(viewModel));
        }
コード例 #2
0
        public async Task <StockScore> GetTrendingStockScore(string stockCode)
        {
            var score        = new StockScore();
            var perfectScore = _settingRepository.GetSettingValue <decimal>(SettingNames.Score_Trending);

            var trendingStocks = await _investagramsApiService.GetTrendingStocks();

            //maybe add how frequent this stock is already on the market. if more than 3 days then give less score
            if (trendingStocks.Any(x => x.Stock.StockCode == stockCode))
            {
                score.AddReason(perfectScore, "Trending stock");
            }

            return(score);
        }
コード例 #3
0
        public void SaveLatestStockUpdate()
        {
            var stocks        = new List <ScreenerResponse>();
            var realTimePrice = new List <RealTimePrice>();

            var events = new List <Event>();

            ClearCache();

            //Save stocks
            var tasks = new List <Task>
            {
                Task.Run(async() => await _investagramsApiService.GetAllLatestStocks()).ContinueWith(x =>
                {
                    stocks.AddRange(x.Result);
                    AddEvents(x.Result.OrderByDescending(e => e.Volume).Take(10), events, EventTypes.HighestVolume);
                }),
                Task.Run(async() => await _investagramsApiService.GetAllActiveStockPriceRealTime()).ContinueWith(x =>
                {
                    realTimePrice.AddRange(x.Result);
                    AddEvents(x.Result.OrderByDescending(e => e.Trades).Take(10), events, EventTypes.HighestTrade);
                }),

                //adding events
                Task.Run(async() => await _investagramsApiService.GetMarketStatus(DateTime.Now)).ContinueWith(x =>
                {
                    AddEvents(x.Result.MostActive, events, EventTypes.MostActive);
                    AddEvents(x.Result.TopGainer, events, EventTypes.TopWinner);
                    AddEvents(x.Result.TopLoser, events, EventTypes.TopLoser);
                }),

                Task.Run(async() => await _investagramsApiService.Get52WeekLow()).ContinueWith(x => AddEvents(x.Result, events, EventTypes._52WeekLow)),
                Task.Run(async() => await _investagramsApiService.GetOversoldStocks()).ContinueWith(x => AddEvents(x.Result, events, EventTypes.Oversold)),
                Task.Run(async() => await _investagramsApiService.GetTrendingStocks()).ContinueWith(x => AddEvents(x.Result, events, EventTypes.Trending)),
                Task.Run(async() => await _investagramsApiService.GreenVolume()).ContinueWith(x => AddEvents(x.Result, events, EventTypes.GreenVolume)),
            };

            Task.WaitAll(tasks.ToArray());

            if (stocks == null)
            {
                throw new System.Exception("Please update investa cookie");
            }

            SaveStocks(stocks, realTimePrice);
            SaveEvents(events);
        }
コード例 #4
0
        public async Task <ActionResult> TrendingNow()
        {
            var model = await _investagramsApi.GetTrendingStocks();

            return(View(model));
        }