static async Task <int> GetCurrentActiveTradersCert(string stockName, string stockDirection)
        {
            List <int> totalTraders = new List <int>();

            foreach (var item in _tradingLinks)
            {
                var request = await client.GetAsync(item);

                var res = await request.Content.ReadAsStringAsync();

                _htmlDoc.LoadHtml(res);

                var elementType = _htmlDoc.DocumentNode
                                  .SelectNodes($"//*[@class='border fLeft XSText rightAlignText highlightOnHover thickBorderBottom']")
                                  .FirstOrDefault().ChildNodes.ElementAt(59).InnerText;



                totalTraders.Add(Int32.Parse(elementType));
            }
            AvanzaRepo.InsertStockData(new StockObject()
            {
                Name = stockName, Type = stockDirection, Price = totalTraders.Sum(), FetchDate = startDate
            });

            _tradingLinks.Clear();
            return(0);
        }
        //static async Task<int> GetIndexDataLagging(string indexObject, string docPath)
        //{
        //    HtmlDocument _htmlDocx = new HtmlDocument();
        //    var request = await client.GetAsync(indexObject);
        //    var res = await request.Content.ReadAsStringAsync();
        //    _htmlDocx.LoadHtml(res);

        //    var node = _htmlDocx.DocumentNode
        //            .SelectNodes($"//*[@id='surface']/div[2]/div/div/div/ul/li[3]/span[2]/span").FirstOrDefault().InnerText;



        //    var indexPrice = node.Replace(".", ",");
        //    indexPrice = indexPrice.Remove(5);
        //    indexPrice = indexPrice.Replace(",", "");
        //    indexPrice = Regex.Replace(indexPrice, @"\s+", "");

        //    Repository.inserttest(new StockObject() {Name = "OMXS30Lagging" ,Type="OMXS30Lagging", Price = Convert.ToInt32(indexPrice) });

        //    return 0;
        //}


        static async Task <int> GetIndexData(string indexObject, string docPath)
        {
            HtmlDocument _htmlDocx = new HtmlDocument();
            var          request   = await client.GetAsync(indexObject);

            var res = await request.Content.ReadAsStringAsync();

            _htmlDocx.LoadHtml(res);

            var node = _htmlDocx.DocumentNode
                       .SelectNodes($"//*[@id='cnbc-contents']/div/div[3]/div[3]/div[1]/div[2]/div/div[1]/div/table/tbody/tr[5]/td[1]/span[1]").FirstOrDefault().InnerText;



            //var indexPrice = node.Replace(".", ",");

            //indexPrice = indexPrice.Remove(5);
            //indexPrice = indexPrice.Replace(",", "");
            //indexPrice = Regex.Replace(indexPrice, @"\s+", "");

            var indexPrice = node.Replace(".", ",");

            indexPrice = indexPrice.Remove(5);
            indexPrice = indexPrice.Replace(",", "");
            indexPrice = Regex.Replace(indexPrice, @"\s+", "");
            AvanzaRepo.InsertStockData(new StockObject()
            {
                Name = "OMXS30", Type = "OMXS30", Price = Convert.ToInt32(indexPrice), FetchDate = startDate
            });

            return(0);
        }
        static async Task <int> GetCurrentActiveTraders(string stockName, string stockDirection)
        {
            List <int> totalTraders = new List <int>();

            foreach (var item in _tradingLinks)
            {
                var request = await client.GetAsync(item);

                var res = await request.Content.ReadAsStringAsync();

                _htmlDoc.LoadHtml(res);

                var elementType = _htmlDoc.DocumentNode
                                  .SelectNodes($"//*[@class='secondaryInfo border XSText noTopBorder highlightOnHover']")
                                  .FirstOrDefault().ChildNodes.Count();

                var tradingCount = "";


                // Different layouts for some futures.
                if (elementType == 41)
                {
                    tradingCount = _htmlDoc.DocumentNode
                                   .SelectNodes($"//*[@class='secondaryInfo border XSText noTopBorder highlightOnHover']")
                                   .FirstOrDefault().ChildNodes.ElementAt(31).InnerText;
                }
                else
                {
                    tradingCount = _htmlDoc.DocumentNode
                                   .SelectNodes($"//*[@class='secondaryInfo border XSText noTopBorder highlightOnHover']")
                                   .FirstOrDefault().ChildNodes.ElementAt(35).InnerText;
                }

                totalTraders.Add(Int32.Parse(tradingCount));
            }
            AvanzaRepo.InsertStockData(new StockObject()
            {
                Name = stockName, Type = stockDirection, Price = totalTraders.Sum(), FetchDate = startDate
            });


            _tradingLinks.Clear();
            return(0);
        }
Exemple #4
0
        public List <string> GetTradingDates()
        {
            var tradingData = AvanzaRepo.GetTradingDays().Select(e => e.FetchDate.ToString()).ToList();

            return(tradingData);
        }
Exemple #5
0
        public static List <StockObject> GetTradingHistory(string ticker)
        {
            var tradingData = AvanzaRepo.GetData().Where(e => e.Name == ticker).ToList();

            return(tradingData);
        }