Exemple #1
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);
        }