private void AppendDataToFile(Worksheet wSheet, int startLine, string type) { try { for (var i = 0; i < dropList.Count; i++) { ELWFMDropModel dropTemp = (ELWFMDropModel)dropList[i]; ((Range)wSheet.Cells[startLine, 1]).NumberFormat = "@"; wSheet.Cells[startLine, 1] = Convert.ToDateTime(dropTemp.UpdateDate).ToString("dd-MMM-yy", new CultureInfo("en-US")); ((Range)wSheet.Cells[startLine, 2]).NumberFormat = "@"; wSheet.Cells[startLine, 2] = Convert.ToDateTime(dropTemp.EffectiveDate).ToString("dd-MMM-yy", new CultureInfo("en-US")); wSheet.Cells[startLine, 3] = dropTemp.RIC; wSheet.Cells[startLine, 4] = dropTemp.Type; wSheet.Cells[startLine, 5] = dropTemp.IDNDisplayName; wSheet.Cells[startLine, 6] = dropTemp.ISIN; ((Range)wSheet.Cells[startLine, 7]).NumberFormat = "@"; wSheet.Cells[startLine, 7] = dropTemp.Ticker; wSheet.Cells[startLine, 8] = dropTemp.MaturityDate; wSheet.Cells[startLine, 9] = dropTemp.Comment; if (type.Equals("master")) { wSheet.Cells[startLine, 10] = dropTemp.OrgSource; wSheet.Cells[startLine, 11] = dropTemp.Publisher; } startLine++; } } catch (Exception ex) { string msg = "Error found in AppendDataToFile() : \r\n" + ex.ToString(); Logger.Log(msg, Logger.LogType.Warning); return; } }
private void FormatELWFMDropModel() { try { for (var i = 0; i < dropList.Count; i++) { ELWFMDropModel drop = (ELWFMDropModel)dropList[i]; //미래1507OCI머티콜 char[] temp_array = drop.OrgSource.ToCharArray(); string str_issuername = ""; foreach (var item in temp_array) { int asciiCode = (int)item; if (asciiCode > 47 && asciiCode < 58) { break; } str_issuername += item; } int no = 0; for (var j = 0; j < temp_array.Length; j++) { int asciiCode = (int)temp_array[j]; if (asciiCode > 47 && asciiCode < 58) { no = j; break; } } string CharLen = drop.OrgSource.Substring(no, 4).Trim().ToString(); drop.Type = "WNT"; string shortname = ""; KoreaIssuerInfo issuer = KoreaIssuerManager.SelectIssuer(str_issuername); if (issuer != null) { drop.Ticker = issuer.IssuerCode2 + CharLen; drop.RIC = issuer.IssuerCode2 + CharLen + ".KS"; shortname = issuer.IssuerCode4; } string tempCompany = string.Empty; //현대1882삼성엔지콜 if (!drop.OrgSource.Contains("조기종료")) { tempCompany = drop.OrgSource; drop.Comment = "Premature"; } else { tempCompany = drop.OrgSource.Replace("조기종료", ""); drop.Comment = "KOBA Drop"; } string last = tempCompany.Substring((no + 4)).Trim().ToString(); string str_underlying_Dsply_Nmll = last.Substring(0, (last.Length - 1)).Trim().ToString(); if (str_underlying_Dsply_Nmll == "KOSPI200") { str_underlying_Dsply_Nmll = "코스피"; } else if (str_underlying_Dsply_Nmll == "스탠차") { str_underlying_Dsply_Nmll = "스탠다드차타드"; } else if (str_underlying_Dsply_Nmll == "IBK") { str_underlying_Dsply_Nmll = "아이비케이"; } else if (str_underlying_Dsply_Nmll == "HMC") { str_underlying_Dsply_Nmll = "에이치엠씨"; } else if (str_underlying_Dsply_Nmll == "KB") { str_underlying_Dsply_Nmll = "케이비"; } string str_call_or_put = last.Substring((last.Length - 1)).Trim().ToString(); string idn_name = "***"; KoreaUnderlyingInfo underlying = KoreaUnderlyingManager.SelectUnderlying(str_underlying_Dsply_Nmll, KoreaNameType.KoreaNameForDrop); if (underlying == null) { Logger.Log("Can not find underlying info with Korea Name for Drop:" + str_underlying_Dsply_Nmll + ". Please input the ISIN.", Logger.LogType.Warning); string isin = InputISIN.Prompt(str_underlying_Dsply_Nmll, "Korea Name For Drop"); if (!string.IsNullOrEmpty(isin)) { underlying = KoreaUnderlyingManager.SelectUnderlyingByISIN(isin); KoreaUnderlyingManager.UpdateKoreaNameDrop(str_underlying_Dsply_Nmll, isin); } } if (underlying != null) { idn_name = underlying.IDNDisplayNamePart; } if (drop.Comment == "KOBA Drop") { idn_name += "KO"; } if (str_call_or_put == "콜") { str_call_or_put = "C"; } else if (str_call_or_put == "풋") { str_call_or_put = "P"; } string _idn_display_name = (shortname + CharLen + idn_name + str_call_or_put).ToString(); drop.IDNDisplayName = _idn_display_name; if (str_issuername == "스탠차") { str_issuername = "스탠다드차타드"; } if (str_issuername == "IBK") { str_issuername = "아이비케이"; } if (str_issuername == "HMC") { str_issuername = "에이치엠씨"; } if (str_issuername == "KB") { str_issuername = "케이비"; } //우리1C83삼성테크콜 drop.Issuername = str_issuername; drop.Num = "제" + CharLen + "호"; } } catch (Exception ex) { string msg = "Error found in _ELWFMDropModelFormat() : " + ex.ToString(); Logger.Log(msg, Logger.LogType.Error); } }
private void GrabOrgSourceDataFromWebpage() { try { string startDate = configObj.StartDate; string endDate = configObj.EndDate; string uri = "http://kind.krx.co.kr/disclosure/disclosurebystocktype.do"; //string postData = string.Format("method=searchDisclosureByStockTypeSub¤tPageSize=15&pageIndex=1&menuIndex=3&orderIndex=1&forward=disclosurebystocktype_sub&elwIsuCd=&elwUly=&lpMbr=&corpNameList=&marketType=&fromData={0}&toData={1}&reportNm=&elwRsnClss=0914&elwRsnClss=0912&elwRsnClss=0915&elwRsnClss=0910", startDate, endDate); string postData = String.Format("method=searchDisclosureByStockTypeElwSub¤tPageSize=15&pageIndex={0}&orderMode=1&orderStat=D&forward=disclosurebystocktype_elw_sub&elwIsuCd=&elwUly=&lpMbr=&corpNameList=&fromDate={1}&toDate={2}&reportNm=%EC%83%81%EC%9E%A5%ED%8F%90%EC%A7%80", 0, startDate, endDate); string pageSource = WebClientUtil.GetDynamicPageSource(uri, 180000, postData); HtmlAgilityPack.HtmlDocument htc = new HtmlAgilityPack.HtmlDocument(); if (!string.IsNullOrEmpty(pageSource)) { htc.LoadHtml(pageSource); } if (htc != null) { HtmlNode tbodyNode = htc.DocumentNode.SelectNodes("//table")[0].SelectSingleNode(".//tbody"); HtmlNodeCollection nodeCollections = tbodyNode.SelectNodes(".//tr"); int count = nodeCollections.Count; for (var i = 0; i < count; i++) { var item = nodeCollections[i] as HtmlNode; HtmlNode titleNode = item.SelectSingleNode(".//td[4]/a"); if (titleNode == null) { continue; } string title = titleNode.InnerText.Trim().ToString(); if (!string.IsNullOrEmpty(title) && title.Equals("주식워런트증권 상장폐지조치")) { string companyname = item.SelectSingleNode(".//td[3]").InnerText; string attribute = string.Empty; attribute = item.SelectSingleNode(".//td[4]/a").Attributes["onclick"].Value.Trim().ToString(); attribute = attribute.Split('(')[1].Split(',')[0].Trim(new char[] { ' ', '\'', ',' }).ToString(); string url = string.Format("http://kind.krx.co.kr/common/disclsviewer.do?method=search&acptno={0}&docno=&viewerhost=&viewerport=", attribute); System.Threading.Thread.Sleep(2000); string source = WebClientUtil.GetDynamicPageSource(url, 300000, null); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); if (!string.IsNullOrEmpty(source)) { doc.LoadHtml(source); } if (doc != null) { //string parameter = doc.DocumentNode.SelectSingleNode(".//div/select[@id='mainDocId']/option[2]").Attributes["value"].Value.Trim().ToString(); String parameter = doc.DocumentNode.SelectSingleNode(".//select[@id='mainDoc']/option[2]").Attributes["value"].Value.Trim().ToString(); parameter = parameter.Trim().ToString().Replace("|Y", ""); attribute = attribute.Insert(4, "/").Insert(7, "/").Insert(10, "/").Trim().ToString(); url = String.Format("http://kind.krx.co.kr/external/{0}/{1}/68955.htm", attribute, parameter); doc = WebClientUtil.GetHtmlDocument(url, 300000, null); if (doc != null) { string str_pre = doc.DocumentNode.SelectSingleNode(".//pre").InnerText.Trim().ToString(); str_pre = str_pre.Trim().ToString(); int str_judge_start_pos = str_pre.IndexOf("상장폐지사유") + "상장폐지사유".Length; string str_judge = FormatDataWithPos(str_judge_start_pos, str_pre); if (str_judge != "최종거래일 도래") { int str_effective_date_start_pos = str_pre.IndexOf("상장폐지일") + "상장폐지일".Length; string str_effective_date = FormatDataWithPos(str_effective_date_start_pos, str_pre); int str_company_start_pos = str_pre.IndexOf("상장폐지 주식워런트증권 종목명") + "상장폐지 주식워런트증권 종목명".Length; //33 string preLeft = str_pre.Substring(str_company_start_pos); int indexNum = 1; string indexSuffix = "."; string pattern = @"\n.*?(?<IndexNum>\d).*?상장폐지 주식워런트증권 종목명"; Regex regex = new Regex(pattern); Match match = regex.Match(str_pre); if (match.Success) { indexNum = Convert.ToInt16(match.Groups["IndexNum"].Value); indexSuffix = match.Value.Replace("상장폐지 주식워런트증권 종목명", "").Replace(indexNum.ToString(), "").Trim(' ', '\n'); } string nextIndex = (indexNum + 1).ToString() + indexSuffix; int strCompanyEndPos = preLeft.IndexOf(nextIndex); string str_company_arr = str_pre.Substring(str_company_start_pos, strCompanyEndPos).Trim('\n', '\r', '\t', ' '); string[] company_arr = str_company_arr.TrimStart(new char[] { '-', ' ', '▶' }).Split('\n'); for (var x = 0; x < company_arr.Length; x++) { ELWFMDropModel ELWDrop = new ELWFMDropModel(); ELWDrop.OrgSource = company_arr[x].Trim(new Char[] { '-', ' ', '▶' }).ToString(); ELWDrop.EffectiveDate = str_effective_date.Trim().ToString(); ELWDrop.UpdateDate = ELWDrop.EffectiveDate; ELWDrop.Publisher = companyname; dropList.Add(ELWDrop); } } } } } } } } catch (Exception ex) { string msg = "Error found in GrabOrgSourceDataFromWebpage() : \r\n" + ex.ToString(); Logger.Log(msg, Logger.LogType.Error); } }