/// <summary> /// Execute a Reader command to the MSQL database /// </summary> /// <param name="cmdString"></param> /// <returns></returns> public static SecurityList ExecuteReader(string cmdString) { SecurityList mSecurityList = new SecurityList(); MySqlConnection connection = new MySqlConnection(myConnPath); connection.Open(); MySqlCommand cmd = new MySqlCommand(cmdString, connection); MySqlDataReader HistReader = cmd.ExecuteReader(); while (HistReader.Read()) { Security tempSecurity = new Security { ConId = HistReader.GetInt32(0), Symbol = HistReader.GetString(1), SecType = Security.SecurityType.STK }; mSecurityList.Add(tempSecurity); Log.Data(0, string.Format("DB.Read Symbol={0,-10} ConId={1,-10} Type={2,-5}", tempSecurity.Symbol, tempSecurity.ConId, tempSecurity.SecType)); } HistReader.Close(); connection.Close(); return(mSecurityList); }
/// <summary> /// Load all of the securites from the database into a table /// </summary> public static SecurityList GetAllSecurities() { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Log.Info(0, string.Format("Start GetAllSecurities")); SecurityList mSecurityList = new SecurityList(); string cmdString = "SELECT DISTINCT conid, ticker FROM " + DB.myHistTable; mSecurityList = DB.ExecuteReader(cmdString); stopwatch.Stop(); Log.Info(3, string.Format("End GetAllSecurites {0} Securities Loaded Time={1:N2}", mSecurityList.Contracts.Count, stopwatch.Elapsed.TotalMilliseconds / 1000)); return(mSecurityList); }
/// <summary> /// Call the DB and return the most active for that day /// </summary> /// <param name="date">Date</param> /// <param name="limit">Number of items to return</param> /// <returns></returns> public static SecurityList GetMostActive(string date, int limit) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Log.Info(3, string.Format("Start GetMostActives")); SecurityList mSecurityList = new SecurityList(); string cmdString = "SELECT conid, ticker, volume FROM " + DB.myHistTable + " WHERE tdate='" + date + "' ORDER BY volume DESC LIMIT " + limit.ToString(); mSecurityList = DB.ExecuteReader(cmdString); stopwatch.Stop(); Log.Info(3, string.Format("End GetMostActives Time={0:N3}", stopwatch.Elapsed.TotalMilliseconds / 1000)); return(mSecurityList); }
/// <summary> /// Attempts to add a SecurityList to the database /// </summary> /// <param name="newSecurityList"></param> /// <returns></returns> public static int AddSecurityList(SecurityList newSecurityList) { int numberAdded = 0; Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Log.Info(0, string.Format("Start AddList")); foreach (Security addSecurity in newSecurityList.Contracts) { if (DataRequests.GetSymbol(addSecurity.ConId) == null) { if (AddSecurity(addSecurity)) { numberAdded++; } } } stopwatch.Stop(); Log.Info(0, string.Format("End AddList - Added {0} Time={1}", numberAdded, stopwatch.Elapsed.TotalMilliseconds)); return(numberAdded); }