コード例 #1
0
        public async Task AddPopularity()
        {
            List <string> symbols = new List <string>();

            using (var client = new HttpClient())
            {
                var url      = new Uri("https://robintrack.net/api/largest_popularity_changes?hours_ago=72&limit=50&percentage=false&min_popularity=50&start_index=0");
                var response = await client.GetAsync(url);

                string json;
                using (var content = response.Content)
                {
                    json = await content.ReadAsStringAsync();
                }

                IEnumerable <PopularityDto> stocks = JsonConvert.DeserializeObject <PopularityDto[]>(json);
                foreach (var stock in stocks)
                {
                    var popularStock = new PopularityEf();
                    popularStock.StartPopularity      = stock.Start_Popularity;
                    popularStock.EndPopularity        = stock.End_Popularity;
                    popularStock.PopularityDifference = stock.Popularity_Difference;
                    popularStock.Name        = stock.Name;
                    popularStock.Symbol      = stock.Symbol;
                    popularStock.CreatedTime = DateTime.Now;

                    _popularityContext.Popularity.Add(popularStock);
                    await _popularityContext.SaveChangesAsync();

                    symbols.Add(popularStock.Symbol);
                }
            }
        }
コード例 #2
0
        public async Task AddProfile()
        {
            var lstsymbols = _popularityContext.PopularStock.Select(s => s.Symbol).Distinct().ToList();
            var lstprofile = _popularityContext.StockProfile.ToList();
            var test       = Environment.GetEnvironmentVariable("FinancialModellingApiKey");
            var num        = 0;

            foreach (var symbol in lstsymbols)
            {
                using (var client = new HttpClient())
                {
                    var url      = new Uri($"https://financialmodelingprep.com/api/v3/profile/{symbol}?apikey={test}");
                    var response = await client.GetAsync(url);

                    string json;
                    using (var content = response.Content)
                    {
                        json = await content.ReadAsStringAsync();
                    }
                    if (json.Length != 0)
                    {
                        IEnumerable <StockProfileEF> stocks = JsonConvert.DeserializeObject <StockProfileEF[]>(json);

                        foreach (var stock in stocks)
                        {
                            if (lstprofile.Where(s => s.Symbol == stock.Symbol).Count() == 0)
                            {
                                var stockProfile = new StockProfileEF();
                                stockProfile.Symbol            = stock.Symbol;
                                stockProfile.Price             = Math.Round(stock.Price, 2);
                                stockProfile.Beta              = stock.Beta;
                                stockProfile.VolumeAvg         = stock.VolumeAvg;
                                stockProfile.MarketCap         = stock.MarketCap;
                                stockProfile.LastDividend      = stock.LastDividend;
                                stockProfile.PriceRange        = stock.PriceRange;
                                stockProfile.CompanyName       = stock.CompanyName;
                                stockProfile.Exchange          = stock.Exchange;
                                stockProfile.ExchangeShortName = stock.ExchangeShortName;
                                stockProfile.Industry          = stock.Industry;
                                stockProfile.Website           = stock.Website;
                                stockProfile.Description       = stock.Description;
                                stockProfile.CEO               = stock.CEO;
                                stockProfile.Sector            = stock.Sector;
                                stockProfile.Country           = stock.Country;
                                stockProfile.FullTimeEmployees = stock.FullTimeEmployees;
                                stockProfile.CompanyImage      = stock.CompanyImage;

                                _popularityContext.StockProfile.Add(stockProfile);
                                await _popularityContext.SaveChangesAsync();
                            }
                        }
                    }
                }
            }
        }
コード例 #3
0
        public async Task GetStockVolume(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = Route)] HttpRequest req,
            ILogger log)
        {
            var lstsymbols = _popularityContext.Popularity.Select(s => s.Symbol).Distinct().ToList();
            var test       = Environment.GetEnvironmentVariable("FinancialModellingApiKey");
            var num        = 0;

            foreach (var symbol in lstsymbols)
            {
                using (var client = new HttpClient())
                {
                    var url      = new Uri($"https://financialmodelingprep.com/api/v3/historical-chart/1hour/{symbol}?apikey={test}");
                    var response = await client.GetAsync(url);

                    string json;
                    using (var content = response.Content)
                    {
                        json = await content.ReadAsStringAsync();

                        log.LogInformation($"Here is the json: {json}");
                    }
                    if (json.Length != 0)
                    {
                        IEnumerable <StockVolumeDto> stocks = JsonConvert.DeserializeObject <StockVolumeDto[]>(json).Take(10);
                        foreach (var stock in stocks)
                        {
                            log.LogInformation($"Here is the stocks: {stock}");
                            var popularStockVolume = new PopularityStockVolumeEf();

                            popularStockVolume.Date   = stock.Date;
                            popularStockVolume.Open   = stock.Open;
                            popularStockVolume.Close  = stock.Close;
                            popularStockVolume.High   = stock.High;
                            popularStockVolume.Low    = stock.Low;
                            popularStockVolume.Symbol = symbol;
                            popularStockVolume.Volume = stock.Volume;
                            _popularityContext.PopularStock.Add(popularStockVolume);
                            await _popularityContext.SaveChangesAsync();
                        }
                    }
                }
            }
        }
コード例 #4
0
        public async Task <IActionResult> AddPopularity(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = Route)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Getting the popularity info");
            List <string> symbols = new List <string>();

            using (var client = new HttpClient())
            {
                var url      = new Uri("https://robintrack.net/api/largest_popularity_changes?hours_ago=72&limit=50&percentage=false&min_popularity=50&start_index=0");
                var response = await client.GetAsync(url);

                string json;
                using (var content = response.Content)
                {
                    json = await content.ReadAsStringAsync();
                }

                IEnumerable <PopularityDto> stocks = JsonConvert.DeserializeObject <PopularityDto[]>(json);
                foreach (var stock in stocks)
                {
                    var popularStock = new PopularityEf();
                    popularStock.StartPopularity      = stock.Start_Popularity;
                    popularStock.EndPopularity        = stock.End_Popularity;
                    popularStock.PopularityDifference = stock.Popularity_Difference;
                    popularStock.Name        = stock.Name;
                    popularStock.Symbol      = stock.Symbol;
                    popularStock.CreatedTime = DateTime.Now;

                    _popularityContext.Popularity.Add(popularStock);
                    await _popularityContext.SaveChangesAsync();

                    symbols.Add(popularStock.Symbol);
                }



                return(new OkObjectResult(stocks));
            }
        }