Example #1
0
        static void TestSp500()
        {
            string[]      sp500  = InvestingToolkit.GetEquityGroupAsync(EquityGroup.SP500).Result;
            List <string> Errors = new List <string>();
            int           t      = 0;

            foreach (string s in sp500)
            {
                Console.Write("Working on " + s + "... ");
                t = t + 1;
                try
                {
                    EquityStatisticalData esd = EquityStatisticalData.CreateAsync(s).Result;
                    float pdone = (float)t / (float)sp500.Length;
                    Console.WriteLine("success... " + pdone.ToString("#0.0%"));
                }
                catch (Exception e)
                {
                    Console.WriteLine("FAILURE! " + e.Message);
                    Errors.Add(s);
                }
            }


            Console.WriteLine("Done!");
            Console.WriteLine("Critical errors:");
            foreach (string s in Errors)
            {
                Console.WriteLine(s);
            }
        }
Example #2
0
 static void TestOne()
 {
     do
     {
         Console.WriteLine("Symbol?");
         string s = Console.ReadLine();
         try
         {
             EquityStatisticalData esd = EquityStatisticalData.CreateAsync(s).Result;
             string json = JsonConvert.SerializeObject(esd);
             Console.WriteLine(json);
         }
         catch
         {
             Console.WriteLine("Failure!");
         }
     } while (true);
 }
Example #3
0
        public async static Task <HttpResponseMessage> GetStockStatisticalData([HttpTrigger(AuthorizationLevel.Anonymous, "get")] HttpRequest req, ILogger log)
        {
            log.LogInformation("New request received");
            string symbol = req.Query["symbol"];

            if (symbol == null || symbol == "")
            {
                log.LogInformation("Parameter 'symbol' not present as part of request. Ending.");
                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.BadRequest);
                hrm.Content = new StringContent("Fatal failure. Parameter 'symbol' not provided. You must provide a stock symbol to return data for.");
                return(hrm);
            }
            symbol = symbol.Trim().ToUpper();
            log.LogInformation("Symbol requested: '" + symbol + "'");

            //Download data
            EquityStatisticalData ToReturn = null;

            try
            {
                log.LogInformation("Attemping to download statistical data for '" + symbol + "'.");
                ToReturn = await EquityStatisticalData.CreateAsync(symbol.Trim().ToUpper());
            }
            catch
            {
                log.LogInformation("Error while downloading statistical data for stock '" + symbol + "'.");
                HttpResponseMessage hrm = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                hrm.Content = new StringContent("Fatal failure. Unable to download statistical data for stock with symbol '" + symbol + "'.");
                return(hrm);
            }

            //Return it
            string json = JsonConvert.SerializeObject(ToReturn);
            HttpResponseMessage fhrm = new HttpResponseMessage(HttpStatusCode.OK);

            fhrm.Content = new StringContent(json, Encoding.UTF8, "application/json");
            return(fhrm);
        }