예제 #1
0
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cfb.Ping("ru.investing.com") == true)   //проверяем доступ к ресурсу
            {
                //заносим значение выбранного торгового инструмента в переменную Instrument
                Transport.Instrument = comboBox2.Text;
                NameValueCollection Investing;
                Investing = ConfigurationManager.GetSection("appSettings_Investing") as NameValueCollection;
                string url = Investing.Get(Transport.Instrument);

                //уменьшить время ожидания завершения функций программы. Однако, все равно необходимо дождаться завершения данного потока
                Thread thrad = new Thread(() =>
                {
                    TC.ReadyNews(url);
                });
                thrad.Start();

                Thread thrad1 = new Thread(() =>
                {
                    TC.ReadyOpinion(url);
                });
                thrad1.Start();
                thrad.Join();
                thrad1.Join();

                listBox1.Items.Clear();

                if (Transport.List_news.Count != 0)
                {
                    for (int i = 0; i < Transport.List_news.Count; i++)
                    {
                        listBox1.Items.Add(Transport.List_news[i]);
                    }
                }
                else
                {
                    listBox1.Items.Add("Новости по данному инструменту не найдены");
                }


                listBox4.Items.Clear();

                if (Transport.List_opinion.Count != 0)
                {
                    for (int i = 0; i < Transport.List_opinion.Count; i++)
                    {
                        listBox4.Items.Add(Transport.List_opinion[i]);
                    }
                }
                else
                {
                    listBox1.Items.Add("Новости по данному инструменту не найдены");
                }
            }
        }
예제 #2
0
        public static void InvestingTests_CalculateYears_RandomTest([Random(1, 10, 98)] int x)
        {
            Random r         = new Random();
            double principal = (r.NextDouble() * 10000);

            //double interest = (0.05);
            double interest = (r.NextDouble() * 1);

            //double tax = (0.18);
            double tax = (r.NextDouble() * 0.21);

            //double desiredPrincipal = principal + 100;
            double desiredPrincipal = (r.NextDouble() * 10000) + principal;

            Console.WriteLine("Starting Pricipal " + principal);
            Console.WriteLine("Desired Pricipal " + desiredPrincipal);

            Console.WriteLine("Interest Rate " + interest);
            Console.WriteLine("Tax Rate " + tax);

            Assert.AreEqual(CalculateYears(principal, interest, tax, desiredPrincipal), Investing.CalculateYears(principal, interest, tax, desiredPrincipal));

            Console.WriteLine("Years Required to accumulate Desired Pricipal " + CalculateYears(principal, interest, tax, desiredPrincipal));
        }
예제 #3
0
 public void InvestingTests_CalculateYears_GetNumberOfYears3()
 {
     Assert.AreEqual(0, Investing.CalculateYears(1000, 0.05, 0.18, 1000));
 }
예제 #4
0
 public void InvestingTests_CalculateYears_GetNumberOfYears1()
 {
     Assert.AreEqual(14, Investing.CalculateYears(1000, 0.01625, 0.18, 1200));
 }
예제 #5
0
        /*public string test(string url)
         * {
         *  string text = "";
         *  //text = NewsResponse(url);
         *  //text = Regex.Replace(text,'"'.ToString(), " ", RegexOptions.IgnoreCase);
         *  //text = Myregex.MyTextDelete(text, "<!DOCTYPE html>", "(function () {");
         *  ChromeOptions opt = new ChromeOptions();
         *  opt.AddArgument("headlesSet");
         *  var driver = new ChromeDriver();
         *  //driver.Manage().Window.Minimize();
         *  driver.Navigate().GoToUrl(url);
         *  WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
         *  System.Threading.Thread.Sleep(10000);
         *  text = driver.PageSource;
         *  return text;
         * }*/



        public void Traid_point(string instr, string time, string categories)   //процедура составляет список точек открытия, точек закрытия, точек максимальных и точек минимальных
        {
            NameValueCollection Investing;

            Investing = ConfigurationManager.GetSection("appSettings_API_Libertex") as NameValueCollection;
            string url = Investing.Get("API");

            Investing = ConfigurationManager.GetSection(categories) as NameValueCollection;

            string url_ref = Investing.Get(instr);

            url_ref = Regex.Replace(url_ref, "https://app.libertex.org/products/", "");
            url_ref = Regex.Replace(url_ref, "agriculture/", "");
            url_ref = Regex.Replace(url_ref, "currency/", "");
            url_ref = Regex.Replace(url_ref, "crypto/", "");
            url_ref = Regex.Replace(url_ref, "indexes/", "");
            url_ref = Regex.Replace(url_ref, "energetics/", "");
            url_ref = Regex.Replace(url_ref, "metal/", "");
            url_ref = Regex.Replace(url_ref, "stock/", "");
            url_ref = Regex.Replace(url_ref, "etf/", "");
            url_ref = Regex.Replace(url_ref, "/", "");

            url = url + url_ref + "&interval=" + time;

            var    webClient = new WebClient();
            string listing   = webClient.DownloadString(url);

            //с помощью команд replace уменьшаем количество символов в тексте
            listing = Regex.Replace(listing, "Result", "");
            listing = Regex.Replace(listing, "Error", "");
            listing = Regex.Replace(listing, "CreatedDate", "");
            listing = Regex.Replace(listing, "RateHistory", "");
            listing = Regex.Replace(listing, "null", "");
            listing = Regex.Replace(listing, "ExpirationHistory", "");
            listing = Regex.Replace(listing, "dt", "d");
            listing = Regex.Replace(listing, '"'.ToString(), "");
            listing = Regex.Replace(listing, ",", "*");
            listing = Regex.Replace(listing, "{", "");
            listing = Regex.Replace(listing, "}", "");
            listing = Regex.Replace(listing, "T", " ");
            listing = Regex.Replace(listing, "[[]", "");
            listing = Regex.Replace(listing, "]", "");


            //создаем ряд списков для дальнейшего построения графиков

            Transport.date_time_traid  = new List <string>();
            Transport.open_traid       = new List <decimal>();
            Transport.high_traid       = new List <decimal>();
            Transport.low_traid        = new List <decimal>();
            Transport.close_traid      = new List <decimal>();
            Transport.volatility_traid = new List <int>();

            //цикл перебирает текст, полученный гет запросом, для создания массивов со значениями цены торгового инструмента
            string date       = "";
            string open       = "";
            string high       = "";
            string low        = "";
            string close      = "";
            string volatility = "";
            string flag       = "";

            for (int i = 0; i < listing.Length; i++)
            {
                if (listing[i] == 'd')
                {
                    flag = "date";
                }
                if (listing[i] == 'o')
                {
                    flag = "open";
                }
                if (listing[i] == 'h')
                {
                    flag = "high";
                }
                if (listing[i] == 'l')
                {
                    flag = "low";
                }
                if (listing[i] == 'c')
                {
                    flag = "close";
                }
                if (listing[i] == 'v')
                {
                    flag = "volatility";
                }

                switch (flag)
                {
                case "date":
                {
                    if (listing[i] != '*')
                    {
                        date += listing[i];
                    }

                    if (listing[i] == '*')
                    {
                        date = Regex.Replace(date, "d:", "");
                        if (date != "")
                        {
                            Transport.date_time_traid.Add(date);
                        }
                        date = "";
                    }
                    break;
                }

                case "open":
                {
                    if (listing[i] == '.')
                    {
                        string str = ",";
                        open += str;
                    }
                    else
                    if (listing[i] != '*')
                    {
                        open += listing[i];
                    }


                    if (listing[i] == '*')
                    {
                        open = Regex.Replace(open, " ", "");
                        open = Regex.Replace(open, "o", "");
                        open = Regex.Replace(open, ":", "");
                        if (open != "")
                        {
                            Transport.open_traid.Add(Convert.ToDecimal(open));
                        }
                        open = "";
                    }
                    break;
                }

                case "high":
                {
                    if (listing[i] == '.')
                    {
                        string str = ",";
                        high += str;
                    }
                    else
                    if (listing[i] != '*')
                    {
                        high += listing[i];
                    }


                    if (listing[i] == '*')
                    {
                        high = Regex.Replace(high, " ", "");
                        high = Regex.Replace(high, "h", "");
                        high = Regex.Replace(high, ":", "");
                        if (high != "")
                        {
                            Transport.high_traid.Add(Convert.ToDecimal(high));
                        }
                        high = "";
                    }
                    break;
                }

                case "low":
                {
                    if (listing[i] == '.')
                    {
                        string str = ",";
                        low += str;
                    }
                    else
                    if (listing[i] != '*')
                    {
                        low += listing[i];
                    }


                    if (listing[i] == '*')
                    {
                        low = Regex.Replace(low, " ", "");
                        low = Regex.Replace(low, "l", "");
                        low = Regex.Replace(low, ":", "");
                        if (low != "")
                        {
                            Transport.low_traid.Add(Convert.ToDecimal(low));
                        }
                        low = "";
                    }
                    break;
                }

                case "close":
                {
                    if (listing[i] == '.')
                    {
                        string str = ",";
                        close += str;
                    }
                    else
                    if (listing[i] != '*')
                    {
                        close += listing[i];
                    }


                    if (listing[i] == '*')
                    {
                        close = Regex.Replace(close, " ", "");
                        close = Regex.Replace(close, "c", "");
                        close = Regex.Replace(close, ":", "");
                        if (close != "")
                        {
                            Transport.close_traid.Add(Convert.ToDecimal(close));
                        }
                        close = "";
                    }
                    break;
                }

                case "volatility":
                {
                    if (listing[i] != '*')
                    {
                        volatility += listing[i];
                    }

                    if (listing[i] == '*')
                    {
                        volatility = Regex.Replace(volatility, " ", "");
                        volatility = Regex.Replace(volatility, "v", "");
                        volatility = Regex.Replace(volatility, ":", "");
                        if (volatility != "")
                        {
                            Transport.volatility_traid.Add(Convert.ToInt32(volatility));
                        }
                        volatility = "";
                    }
                    break;
                }
                }
            }
        }
예제 #6
0
 public RootObject()
 {
     investments = new Investing();
 }