void InsertOptionDataIntoDB(LoadingData_Option data) { DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = IP; con = dbManager.CreateConnection(ip, CommonConst.DATABASE_MADVIPER); con.Open(); foreach (LoadingDatum_Option info in data.Data) { /* * 0 code * 1 name * 2 strike * 3 maturity * 4 up_limit * 5 down_limit * */ String query_template = String.Format("insert into option_info ({0}) values ({1})", "code, name, strike, maturity, up_limit, down_limit", "'{0}', '{1}', {2}, {3}, {4}, {5}"); String query = String.Format( query_template, info.Code, info.Name, info.Strike, info.Maturity, info.UpLimit, info.DownLimit); logger.Debug(query); MySqlCommand cmd = new MySqlCommand(query, con); int ret = cmd.ExecuteNonQuery(); if (ret <= 0) { logger.Warn(String.Format("Query: ({0})", query)); } } logger.Info("InsertOptionDataIntoDB is complete..."); } catch (System.Exception ex) { logger.Warn(ex.ToString()); } finally { dbManager.Close(con); } }
LoadingData_Option GetOptionDataFromCP(DateTime maturityFromConfigFile) { LoadingData_Option data = new LoadingData_Option(); DSCBO1Lib.OptionInfo optionInfo = new DSCBO1Lib.OptionInfo(); optionInfo.BlockRequest(); int count = Convert.ToInt32(optionInfo.GetHeaderValue(1)); for (int i = 0; i < count; ++i) { String code = Convert.ToString(optionInfo.GetDataValue(0, i)); String name = Convert.ToString(optionInfo.GetDataValue(1, i)); double strike = Convert.ToDouble(optionInfo.GetDataValue(2, i)); strike = Math.Round(strike, 2); long maturity = Convert.ToInt64(optionInfo.GetDataValue(3, i)); double upLimit = Convert.ToDouble(optionInfo.GetDataValue(4, i)); double downLimit = Convert.ToDouble(optionInfo.GetDataValue(5, i)); if (maturityFromConfigFile.ToString("yyyyMM").CompareTo(maturity.ToString()) != 0) { continue; // 근월물이 아니다. } LoadingDatum_Option datum = new LoadingDatum_Option(); datum.Code = code; datum.Name = name; datum.Strike = strike; datum.Maturity = maturity; datum.UpLimit = upLimit; datum.DownLimit = downLimit; data.Data.Add(datum); } return data; }