public ActionResult Create(Market market)
        {
            if (ModelState.IsValid)
            {
                db.Markets.Add(market);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(market);
        }
Beispiel #2
0
        public List<DailyCandle> GetHistoricalData(DateTime Beg, DateTime Endie, Market m)
        {
            //http://ichart.yahoo.com/table.csv?s=BAS.DE&a=0&b=1&c=2000&d=0&e=31&f=2010&g=w&ignore=.csv

            List<DailyCandle> qt = new List<DailyCandle>();
            string tester = "";

            int a = Beg.Month - 1;
            int b = Beg.Day;
            int c = Beg.Year;

            int d = Endie.Month - 1;
            int e = Endie.Day;
            int f = Endie.Year;

            string yahooURL = @"http://ichart.yahoo.com/table.csv?s=" + m.Symbol + "&a=" + a.ToString() + "&b=" + b.ToString() + "&c=" + c.ToString() + "&d=" + d.ToString() + "&e=" + e.ToString() + "&f=" + f.ToString() + "&g=d&ignore=.csv";

            // Initialize a new WebRequest.
            HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(yahooURL);
            // Get the response from the Internet resource.
            HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
            // Read the body of the response from the server.
            StreamReader strm =
              new StreamReader(webresp.GetResponseStream(), Encoding.ASCII);

            String content = content = strm.ReadLine();
            while ((content = strm.ReadLine()) != null)
            {
                content = content.Replace("\"", "");
                string[] contents = content.ToString().Split(',');
                tester = tester + contents[4] + " - ";
                DailyCandle td = new DailyCandle();
                td.MarketId = m.MarketId;
                td.Date = DateTime.Parse(contents[0]);

                td.Open = decimal.Parse(contents[1]);
                td.High = decimal.Parse(contents[2]);
                td.Low = decimal.Parse(contents[3]);
                td.Close = decimal.Parse(contents[4]);
                try
                {
                    td.Volume = int.Parse(contents[5]);
                }
                catch
                {
                    td.Volume = 0;
                }
                qt.Add(td);

            }
            strm.Close();

            return qt;
        }
 public ActionResult Edit(Market market)
 {
     if (ModelState.IsValid)
     {
         db.Entry(market).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(market);
 }