/// <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> /// Called when all of the bars have been received /// </summary> /// <param name="reqId"></param> public void EndHistoricalBar(int reqId) { myRequests.Release(reqId); int conId = myRequests.GetConId(reqId); int routeId = myRequests.GetRouteId(reqId); string symbol = myRequests.GetSymbol(reqId); if (symbol == null) { Log.Error(3, string.Format("EndHistoricalBar Null Symbol ConId= {0}", conId)); } Security tempSecurity = new Security { ConId = conId, Symbol = symbol, SecType = Security.SecurityType.STK }; switch (routeId) { case 0: // Route = is an update to an existing security in the DB Log.Data(2, string.Format("EndHistoricalBar {0,-10} {1,-8}", conId, symbol)); myBDL.Trim(TradingTime.TradingMinDate, TradingTime.TradingMaxDate); MSQL.WriteBarListDB(reqId, conId, symbol, myBDL, true); break; case 1: // Route = 1 means this is a new security to the DB Log.Data(3, string.Format("EndHistoricalBar Route 1 {0,-10} {1,-8}", conId, symbol)); //Remove any days that our outside our date range myBDL.Trim(TradingTime.TradingMinDate, TradingTime.TradingMaxDate); // Only add if Average Daily Volume is above minimum if (myBDL.CalcAvgVolume() > 2000) { Log.Data(3, string.Format("Added Volume {0,-10} {1,-8} {2,8}", conId, symbol, myBDL.CalcAvgVolume())); MSQL.WriteBarListDB(reqId, conId, symbol, myBDL, true); IB.masterSecurityList.Add(tempSecurity); } else { // Average Daily Volume is too small, do not add to the DB Log.Data(3, string.Format("Skipped Volume {0,-10} {1,-8} {2,8}", conId, symbol, myBDL.CalcAvgVolume())); BlackList.Add(tempSecurity); Program.myIB.myRequests.Delete(reqId); Program.myIB.myBDL.Clear(); } break; default: Log.Error(3, string.Format("RouteId Error = {0}", routeId)); break; } }