Boolean IsSameElwInfo(CP_LoadingDatum_Elw cpInfo, CP_LoadingDatum_Elw dbInfo) { if (cpInfo.UnderlyingCode.CompareTo(dbInfo.UnderlyingCode) != 0) { logger.Warn("{0} != {1}", cpInfo.UnderlyingCode, dbInfo.UnderlyingCode); return false; } if (cpInfo.UnderlyingName.CompareTo(dbInfo.UnderlyingName) != 0) { logger.Warn("{0} != {1}", cpInfo.UnderlyingName, dbInfo.UnderlyingName); return false; } if (cpInfo.Code.CompareTo(dbInfo.Code) != 0) { logger.Warn("{0} != {1}", cpInfo.Code, dbInfo.Code); return false; } if (cpInfo.Name.CompareTo(dbInfo.Name) != 0) { logger.Warn("{0} != {1}", cpInfo.Name, dbInfo.Name); return false; } if (cpInfo._CallPut.CompareTo(dbInfo._CallPut) != 0) { logger.Warn("{0} != {1}", cpInfo._CallPut, dbInfo._CallPut); return false; } if (cpInfo.Maturity != dbInfo.Maturity) { logger.Warn("{0} != {1}", cpInfo.Maturity, dbInfo.Maturity); return false; } if (!Util.IsSameDouble(cpInfo.Strike, dbInfo.Strike)) { logger.Warn("{0} != {1}", cpInfo.Strike, dbInfo.Strike); return false; } if (cpInfo.ChangeRate != dbInfo.ChangeRate) { logger.Warn("{0} != {1}", cpInfo.ChangeRate, dbInfo.ChangeRate); return false; } if (cpInfo.IssuedCount != dbInfo.IssuedCount) { logger.Warn("{0} != {1}", cpInfo.IssuedCount, dbInfo.IssuedCount); return false; } if (cpInfo.RemainDays > dbInfo.RemainDays) { logger.Warn("{0} > {1}", cpInfo.RemainDays, dbInfo.RemainDays); return false; } if (cpInfo.LongCode.CompareTo(dbInfo.LongCode) != 0) { logger.Warn("{0} != {1}", cpInfo.LongCode, dbInfo.LongCode); return false; } return true; }
LoadingData_Elw GetLoadingDataFromDB(DateTime maturity) { LoadingData_Elw data = new LoadingData_Elw(); List<CP_LoadingDatum_Elw> elwInfos = new List<CP_LoadingDatum_Elw>(); String kospi200 = "U180"; String query_template = "select * from elw_info where underlying_code = '{0}' and maturity = {1}"; String query = String.Format(query_template, kospi200, maturity.ToString("yyyyMMdd")); DBManager dbManager = new DBManager(); MySqlConnection con = null; try { String ip = ConfigManager.Ins().Config.GetValue(ConfigKeyConst.DB_SERVER_IP); con = dbManager.CreateConnection(ip, CommonConst.DATABASE_MADVIPER); con.Open(); MySqlCommand cmd = new MySqlCommand(query, con); MySqlDataAdapter dataAdapter = new MySqlDataAdapter(cmd); DataSet ds = new DataSet("query_result"); dataAdapter.Fill(ds, "query_result"); DataRowCollection drc = ds.Tables["query_result"].Rows; if (drc.Count <= 0) { return data; } for (int i = 0; i < drc.Count; ++i) { CP_LoadingDatum_Elw datum = new CP_LoadingDatum_Elw(); DataRow dr = drc[i]; datum.UnderlyingCode = Convert.ToString(dr["underlying_code"]); datum.UnderlyingName = Convert.ToString(dr["underlying_name"]); datum.Code = Convert.ToString(dr["code"]); datum.Name = Convert.ToString(dr["name"]); datum.Maturity = Convert.ToInt64(dr["maturity"]); datum.Strike = Convert.ToDouble(dr["strike"]); datum.ChangeRate = Convert.ToInt32(dr["change_rate"]); datum._CallPut = Convert.ToString(dr["call_put"]); datum.RemainDays = Convert.ToInt64(dr["remain_days"]); datum.Gearing = Convert.ToDouble(dr["gearing"]); datum.IssuedCount = Convert.ToInt64(dr["issued_count"]); datum.LongCode = Convert.ToString(dr["long_code"]); elwInfos.Add(datum); } ds.Clear(); data.Data = elwInfos; } catch (System.Exception ex) { logger.Warn(ex.ToString()); } finally { dbManager.Close(con); } return data; }
Dictionary<String, CP_LoadingDatum_Elw> GetElwInfoFromCP(DateTime maturity) { Dictionary<String, CP_LoadingDatum_Elw> elwInfos = new Dictionary<string, CP_LoadingDatum_Elw>(); String kospi200 = "U180"; CPSYSDIBLib.ElwAll elwAll = new CPSYSDIBLib.ElwAll(); CPUTILLib.CpStockCode cpStockCode = new CPUTILLib.CpStockCode(); // 1. ELW 종목 리스트를 얻어온다. // 2. Kospi200에 해당하는 리스트를 얻어온다. // 3. ELW를 등록한다. elwAll.SetInputValue(0, 1); while (true) { elwAll.BlockRequest(); int count = Convert.ToInt32(elwAll.GetHeaderValue(0)); for (int i = 0; i < count; ++i) { String underlyingCode = Convert.ToString(elwAll.GetDataValue(36, i)); String underlyingName = Convert.ToString(elwAll.GetDataValue(37, i)); if (underlyingCode.CompareTo(kospi200) != 0) { continue; } String code = Convert.ToString(elwAll.GetDataValue(0, i)); String name = Convert.ToString(elwAll.GetDataValue(3, i)); String callPut = Convert.ToString(elwAll.GetDataValue(4, i)); long maturityCP = Convert.ToInt64(elwAll.GetDataValue(6, i)); double strike = Convert.ToDouble(elwAll.GetDataValue(10, i)); int changeRate = Convert.ToInt32(elwAll.GetDataValue(11, i)); double bidPrice = Convert.ToDouble(elwAll.GetDataValue(15, i)); double askPrice = Convert.ToDouble(elwAll.GetDataValue(14, i)); double curPrice = Convert.ToDouble(elwAll.GetDataValue(16, i)); double gearing = Convert.ToDouble(elwAll.GetDataValue(28, i)); long issuedCount = Convert.ToInt64(elwAll.GetDataValue(9, i)); long remainDays = Convert.ToInt32(elwAll.GetDataValue(13, i)); double kockoutPrice = Convert.ToDouble(elwAll.GetDataValue(43, i)); if (maturity.ToString("yyyyMMdd").CompareTo(maturityCP.ToString()) == 0) { if (kockoutPrice > 0) { // 조기종료 버린다. logger.Debug("{0} is discarded in that it is KOBA.", name); continue; } CP_LoadingDatum_Elw datum = new CP_LoadingDatum_Elw(); datum.UnderlyingCode = underlyingCode; datum.UnderlyingName = underlyingName; if (name.ToUpper().Contains("KB") || name.ToUpper().Contains("국민") || name.ToUpper().Contains("케이비") || name.ToUpper().Contains("kb")) { // KB투자증권 버린다. logger.Debug("{0} is discarded in that it is KB.", name); continue; } datum.Code = code; datum.Name = name; datum.Maturity = maturityCP; datum.Strike = strike; datum.ChangeRate = changeRate; datum._CallPut = callPut; datum.RemainDays = remainDays; datum.Gearing = gearing; datum.IssuedCount = issuedCount; datum.LongCode = cpStockCode.CodeToFullCode(code); datum.BidPrice = bidPrice; datum.AskPrice = askPrice; datum.CurPrice = curPrice; elwInfos.Add(datum.Code, datum); } } if (elwAll.Continue == 0) { break; } } return elwInfos; }