public ActionResult Create(DailyCandle dailycandle)
        {
            if (ModelState.IsValid)
            {
                db.DailyCandles.Add(dailycandle);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.MarketId = new SelectList(db.Markets, "MarketId", "Symbol", dailycandle.MarketId);
            return View(dailycandle);
        }
示例#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(DailyCandle dailycandle)
 {
     if (ModelState.IsValid)
     {
         db.Entry(dailycandle).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     ViewBag.MarketId = new SelectList(db.Markets, "MarketId", "Symbol", dailycandle.MarketId);
     return View(dailycandle);
 }
示例#4
0
        public void GapFinder(int marketId)
        {
            using (MarketsDBEntities mde = new MarketsDBEntities())
            {
            //find all candles that don't have a corresponding gap
                var candles = mde.DailyCandles.Where (x => x.MarketId == marketId && x.Gaps.Count == 0);

                foreach (var candle in candles.OrderBy(x=>x.Date))
                {
                    Console.WriteLine("Finding gap for " + candle.Date.ToShortDateString());

                    //1. Find the candle one candle back date-wise

                    int trys = 0;
                    DailyCandle lastCandle = new DailyCandle();
                    DateTime lastDate = candle.Date.AddDays(-1);
                    while (trys < 6 && lastCandle.Date< DateTime.Now.AddYears(-100))
                    {
                        //Console.WriteLine(lastDate.Date.ToShortDateString());

                        if (mde.DailyCandles.Where(x => x.MarketId == marketId && x.Date == lastDate).Count() > 0)
                        {
                            Console.WriteLine("Last candle found.");
                            lastCandle = mde.DailyCandles.Where(x => x.MarketId == marketId && x.Date == lastDate).First();
                        }
                        trys++;
                        lastDate = lastDate.AddDays(-1);
                    }

                    if (lastCandle.Date< DateTime.Now.AddYears(-100))
                        Console.WriteLine("No last candle found!");

                    Console.WriteLine("Last candle: " + lastCandle.Date.ToShortDateString());

                    Gap g = new Gap();
                    g.MarketId = marketId;
                    g.DailyCandleId = candle.DailyCandleId;
                    g.OpenDate = candle.Date;
                    g.GapSize = candle.Open - lastCandle.Close;

                    if (candle.Open >= lastCandle.Close)
                    {
                        g.Direction = "Up";
                        g.GapTop = candle.Open;
                        g.GapBottom = lastCandle.Close;

                        if (candle.Low <= lastCandle.Close)
                        {
                            g.FillDate = candle.Date;
                        }
                    }
                    else
                    {
                        g.Direction = "Down";
                        g.GapTop = lastCandle.Close;
                        g.GapBottom = candle.Open;

                        if (candle.High >= lastCandle.Close)
                        {
                            g.FillDate = candle.Date;
                        }
                    }

                    g.GapExtension = candle.Open + g.GapSize;

                    using (MarketsDBEntities mdeAdder = new MarketsDBEntities())
                    {
                        mdeAdder.Gaps.Add(g);
                        mdeAdder.SaveChanges();
                    }

                }

            }
        }