Пример #1
0
        private void btnTestYahoo_Click(object sender, EventArgs e)
        {
            API.ApiYahoo apiYahoo = new API.ApiYahoo();

            //get historical quotes from yahoo
            // List<API.Candle> mCandle = new List<API.Candle>();
            DateTime dtStart = System.Convert.ToDateTime(dtDateFrom.Text);
            DateTime dtEnd   = System.Convert.ToDateTime(dtDateTo.Text);

            lstRealTimeQuotes.Items.Clear();
            lstTestGoogle.Items.Clear();

            //Convert interval to seconds
            string sFactor = cboInterval.Text.Substring(cboInterval.Text.Length - 1, 1);
            int    seconds = 0;

            if (sFactor == "m")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("m", "")) * 60;
            }
            else if (sFactor == "h")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("h", "")) * 60 * 60;
            }
            else if (sFactor == "d")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("d", "")) * 60 * 60 * 24;
            }
            else if (sFactor == "k")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("wk", "")) * 60 * 60 * 24 * 5;
            }
            else if (sFactor == "o")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("mo", "")) * 60 * 60 * 24 * 5 * 4;
            }

            //pass variables to the historical price.
            var testa = apiYahoo.GetHistoricalPrice(txtSymbol.Text, seconds, dtStart, dtEnd);

            for (int i = 0; i < testa.Count(); i++)
            {
                lstTestGoogle.Items.Add(
                    testa.ElementAt(i).Date + ", " +
                    testa.ElementAt(i).Open + ", " +
                    testa.ElementAt(i).High + ", " +
                    testa.ElementAt(i).Low + ", " +
                    testa.ElementAt(i).Close + ", " +
                    testa.ElementAt(i).Volume
                    );
            }

            //Count the items in historical values
            lblCount.Text = testa.Count().ToString();

            //Get the quote from yahoo
            var testb = apiYahoo.GetQuote("MSFT");

            lstRealTimeQuotes.Items.Add("D: " + testb.Date.ToString("MM/dd/yyyy hh:mm:ss"));
            lstRealTimeQuotes.Items.Add("O: " + testb.Open);
            lstRealTimeQuotes.Items.Add("H: " + testb.High);
            lstRealTimeQuotes.Items.Add("C: " + testb.Close);
            lstRealTimeQuotes.Items.Add("L: " + testb.Low);
            lstRealTimeQuotes.Items.Add("V: " + testb.Volume);
        }
Пример #2
0
        private void butTestBases_Click(object sender, EventArgs e)
        {
            API.ApiYahoo apiYahoo = new API.ApiYahoo();

            //get historical quotes from yahoo
            // List<API.Candle> mCandle = new List<API.Candle>();
            DateTime dtStart = System.Convert.ToDateTime(dtDateFrom.Text);
            DateTime dtEnd   = System.Convert.ToDateTime(dtDateTo.Text);

            lstRealTimeQuotes.Items.Clear();
            lstTestGoogle.Items.Clear();

            //Convert interval to seconds
            string sFactor = cboInterval.Text.Substring(cboInterval.Text.Length - 1, 1);
            int    seconds = 0;

            if (sFactor == "m")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("m", "")) * 60;
            }
            else if (sFactor == "h")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("h", "")) * 60 * 60;
            }
            else if (sFactor == "d")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("d", "")) * 60 * 60 * 24;
            }
            else if (sFactor == "k")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("wk", "")) * 60 * 60 * 24 * 5;
            }
            else if (sFactor == "o")
            {
                seconds = System.Convert.ToInt32(cboInterval.Text.Replace("mo", "")) * 60 * 60 * 24 * 5 * 4;
            }

            //pass variables to the historical price.
            IEnumerable <API.Candle> candleSticks = apiYahoo.GetHistoricalPrice(txtSymbol.Text, seconds, dtStart, dtEnd);



            //NOTE: THIS WILL BE PART OF THE EXECUTION ENGINE



            BaseData oData = new BaseData();

            //Generate a base finder and get all the DERIVED CLASSES of the base class.
            Base          baseFinder     = new Base();
            List <String> DerivedClasses = baseFinder.FindDerivedClasses();

            // Let's just get one of the classes and dynamically create an instance of the class
            // of the derived type!
            String strClass    = DerivedClasses[0];
            Type   DerivedType = baseFinder.DerivedClass(strClass);
            Object mClass      = (object)Activator.CreateInstance(DerivedType);

            //Call methods inside the class, first method will return something by value
            // second method will take parameters and return something from the dynamically created object.
            //System.Reflection.MethodInfo method = DerivedType.GetMethod("FindBase");
            //var somereturnvalue = method.Invoke(mClass, new object[0]);
            System.Reflection.MethodInfo method = DerivedType.GetMethod("FindBase");
            oData = (BaseData)method.Invoke(mClass, new object[] { candleSticks });
            System.Reflection.MethodInfo method2 = DerivedType.GetMethod("Findsomething");
            String param1           = "testing number ";
            int    param2           = 7;
            var    somereturnvalue2 = method2.Invoke(mClass, new object[] { param1, param2 });

            Console.WriteLine("> " + somereturnvalue2);

            // Generate a list of all derived classes (no, not method we are not going to over-populate)
            for (int i = 0; i < DerivedClasses.Count(); i++)
            {
                lstRealTimeQuotes.Items.Add(DerivedClasses[i]);
            }
        }