Beispiel #1
0
        public void ProcessSymbolYChartEps(int total, Company c, com.LandonKey.SocksWebProxy.SocksWebProxy proxy)
        {
            Random r = new Random();

            System.Threading.Thread.Sleep(500 + r.Next(1000));  //Sleep between 500-1500 ms
            EpsData data = YChartsData.GetEpsData(c.Symbol, proxy);
            var     col  = DB.GetCollection <Trading.Company>("data");

            if (data.Quarters.Count > 0)
            {
                c.EarningsQuarters = data.Quarters;
                c.EarningsData     = data.Eps;
                col.Update(c);
            }
            else
            {
                col.Delete(c.Id);
            }

            current++;
            int      left   = total - current;
            double   avgSec = sw.Elapsed.TotalSeconds / current;
            TimeSpan ts     = new TimeSpan(0, 0, (int)(avgSec * left));

            Debug.Nlog("YCharts Eps, " + current.ToString() + "/" + total.ToString() + "\t" + c.Symbol + ", " + ts.ToString() + " left");
        }
Beispiel #2
0
        public static EpsData GetEpsData(string symbol, SocksWebProxy proxy)
        {
            //ProxyConfig pc = new ProxyConfig(IPAddress.Parse("127.0.0.1"), 1080, ip, 1080, ProxyConfig.SocksVersion.Five, "x7212591", "c4gkjs4rSg");

            //var proxy = new SocksWebProxy(pc);
            WebClient client = new WebClient();

            client.Headers.Add("Cache-Control", "no-cache");
            client.CachePolicy = new System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.BypassCache);
            client.Proxy       = proxy;
            //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
            string html     = "";
            int    tryCount = 0;

            while (html.Equals("") && tryCount < 6)
            {
                try
                {
                    html = client.DownloadString("https://ycharts.com/companies/" + symbol + "/eps");
                }
                catch (Exception ex)
                {
                    Trading.Debug.Nlog(symbol + "\n\t" + ex.Message + " \n\t" + ex.InnerException.Message);
                    tryCount++;
                    System.Threading.Thread.Sleep(500);
                    continue;
                }
                break;
            }

            if (html.Equals(""))
            {
                return(new EpsData());
            }


            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(html);
            var             page      = doc.DocumentNode.SelectSingleNode("//body");
            List <HtmlNode> dateNodes = doc.DocumentNode.CssSelect("td.col1").ToList();
            List <HtmlNode> epsNodes  = doc.DocumentNode.CssSelect("td.col2").ToList();


            List <string> dateStrings = dateNodes.Select(x => x.InnerHtml).ToList();
            List <string> epsStrings  = epsNodes.Select(x => x.InnerHtml.Replace(" ", "").Replace("\n", "")).ToList();

            EpsData epsData = new EpsData(dateStrings, epsStrings);

            return(epsData);
        }