public static List <TradingDay> DownloadStocksUsingString(string Ticks, DateTime From) { List <TradingDay> Market = new List <TradingDay>(); int c = 1; HistQuotesDownload dl = new HistQuotesDownload(); dl.Settings.IDs = new string[] { Ticks }; dl.Settings.FromDate = From; dl.Settings.ToDate = DateTime.Today; dl.Settings.Interval = HistQuotesInterval.Daily; Response <HistQuotesResult> resp = dl.Download(); foreach (HistQuotesDataChain hqc in resp.Result.Chains) { foreach (HistQuotesData hqd in hqc) { TradingDay tempday = new TradingDay(hqc.ID, c, hqd.TradingDate.ToLocalTime(), hqd.Open, hqd.Close, hqd.High, hqd.Low, hqd.CloseAdjusted, hqd.PreviousClose, (int)hqd.Volume); c++; Market.Add(tempday); } } return(Market); }
public int GetIndexWeekly(DateTime date) { TradingDay mod = WeeklyHistory.OrderBy(x => Math.Abs(x.TradeDate.Ticks - date.Ticks)).First(); int index = WeeklyHistory.IndexOf(mod); return(index); }
public List <Stock> InitialiseStocks(bool test) { List <Stock> Result = new List <Stock>(); System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(); con.ConnectionString = @"Data Source=(LocalDB)\MSSQLLocalDB; AttachDbFilename=C:\Temp\WOERK.mdf; Integrated Security=True; Connect Timeout=30;"; con.Open(); DbCommand t = con.CreateCommand(); if (test) { Result.Add(new Stock()); Result.Add(new Stock()); Result.Add(new Stock()); Result.Add(new Stock()); Result[0].Ticker = "SGH.AX"; Result[1].Ticker = "BHP.AX"; Result[2].Ticker = "EGH.AX"; Result[3].Ticker = "RFG.AX"; } else { t.Connection = con; t.CommandText = "SELECT DISTINCT Ticker FROM StockHist;"; using (DbDataReader dr = t.ExecuteReader()) { int i = 0; if (dr.HasRows) { while (dr.Read()) { Stock temp = new Stock(); object c = dr.GetValue(0); temp.Ticker = (string)c; Result.Add(temp); i++; } } } } foreach (var c in Result) { c.DailyHistory = new List <TradingDay>(); string temp = "SELECT * FROM StockHist WHERE Ticker = '" + c.Ticker + "';"; t.CommandText = temp; using (DbDataReader dr = t.ExecuteReader()) { int i = 0; if (dr.HasRows) { while (dr.Read()) { object x = dr.GetValue(2); DateTime date = (DateTime)dr.GetValue(2); double Opening = (double)dr.GetValue(3); double Closing = (double)dr.GetValue(4); double High = (double)dr.GetValue(5); double Low = (double)dr.GetValue(6); int Volume = (int)dr.GetValue(7); double PrevClose = (double)dr.GetValue(9); double AdjClose = (double)dr.GetValue(10); TradingDay tempDay = new TradingDay(c.Ticker, i, date, Opening, Closing, High, Low, AdjClose, PrevClose, Volume); c.DailyHistory.Add(tempDay); i++; } } } //c.SortDates(); } //CompanyFinancialHighlights p = new CompanyFinancialHighlights(); //p.ss return(Result); }