Beispiel #1
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Choose 1 for csv or 2 for Json format, \nIf you dont choose anything before 10 secs, the default format in settings file will be selected \n" +
                              "You can change the setting in the app.config folder");
            Option.FormatOption = '1';

            DateTime beginWait = DateTime.Now;

            while (!Console.KeyAvailable && DateTime.Now.Subtract(beginWait).TotalSeconds < 5)
            {
                Thread.Sleep(5000);
            }

            if (!Console.KeyAvailable)
            {
                Console.WriteLine("You didn't press anything! So downloading the default based on settings in config file");
                if (Properties.Settings.Default.OutputFormat.ToLower() == "json")
                {
                    Option.FormatOption = '2';
                }
            }
            else
            {
                Console.WriteLine("You pressed: {0}", Option.FormatOption = Console.ReadKey().KeyChar);
            }

            MarketDataHandler mdh = new YahooFinanceData.MarketDataHandler();

            //Calling the BuildReuest method which sets the parameters and returns the recevied response be formatted
            mdh.FormatOutput(RequestData.BuildRequest());
        }
Beispiel #2
0
        public static List <Contract> BuildRequest()
        {
            string        MarketData;
            StringBuilder marketList = new StringBuilder();

            string filePath = Path.Combine(Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName, @"Entities\MarketList.txt");

            // Iterate through the list of markets present in the file
            using (StreamReader sr = new StreamReader(filePath))
            {
                string temp;
                marketList.Append(sr.ReadLine().Trim());
                while ((temp = sr.ReadLine()) != null)
                {
                    marketList.Append("+");
                    marketList.Append(temp.Trim());
                }
                marketList.Append("&");
            }

            // Set the url with parameters including symbols and the fields required
            using (WebClient web = new WebClient())
            {
                MarketData = web.DownloadString("http://finance.yahoo.com/d/quotes.csv?s=" + marketList + "f=sxl1vc1t1t1");
            }

            // Parse the response and return it
            MarketDataHandler mdh = new YahooFinanceData.MarketDataHandler();

            return(mdh.ParseResponse(MarketData));
        }