예제 #1
0
 public HttpResponseMessage GetHistoricalData(string symbol)
 {
     try
     {
         List<HistoryModel> historyData;
         StockManager manager = new StockManager();
         if (System.Web.HttpContext.Current.Cache[symbol + "history"] != null)
         {
             historyData = System.Web.HttpContext.Current.Cache[symbol + "history"] as List<HistoryModel>;
         }
         else
         {
             historyData = manager.GetHistory(symbol, null, null);
             System.Web.HttpContext.Current.Cache.Add(symbol + "history", historyData, null, DateTime.Now.AddMinutes(20), TimeSpan.Zero, CacheItemPriority.Default, null);
         }
         return Request.CreateResponse(HttpStatusCode.OK, historyData);
         //YqlManager manager = new YqlManager();
         //var quotes = manager.GetHistory(symbol);
         //return Request.CreateResponse(HttpStatusCode.OK, quotes);
     }
     catch (Exception ex)
     {
         return Request.CreateResponse(HttpStatusCode.InternalServerError);
     }
 }
예제 #2
0
 public HttpResponseMessage GetSma(DateTime? startDate, int? avergaeOnDays, string symbol)
 {
     try
     {
         var historyData = System.Web.HttpContext.Current.Cache[symbol + "history"] as List<HistoryModel>;
         if (historyData != null)
         {
             StockManager manager = new StockManager();
             var data = manager.GetSimpleMovingAverage(startDate ?? DateTime.Now.AddYears(-1), 10, historyData);
             return Request.CreateResponse(HttpStatusCode.OK, data);
         }
         else
         {
             return Request.CreateErrorResponse(HttpStatusCode.Gone, new Exception("Please refresh the page!!"));
         }
     }
     catch (Exception ex)
     {
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
     }
 }
예제 #3
0
 public HttpResponseMessage GetStocks(int id)
 {
     StockManager manager = new StockManager();
     var list = manager.GetCompanies(id);
     return Request.CreateResponse(HttpStatusCode.OK, list);
 }
예제 #4
0
        public HttpResponseMessage GetQuote(string symbol)
        {
            try
            {
                StockManager manager = new StockManager();
                var quote = manager.GetQuote(symbol);
                return Request.CreateResponse(HttpStatusCode.OK, quote);

            }
            catch (Exception ex)
            {
                return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex);
            }
        }