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);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Search the ISIN website for given korean name and key word: 보통주 first time: search with koreanName + 보통주. second time: search with koreanName
        /// If mutiple records or no record found. User need to input ISIN.
        /// </summary>
        /// <param name="koreanName">korean name</param>
        /// <param name="times">searched times</param>
        /// <returns>isin</returns>
        public static string GetIsinByName(string koreanName, int times)
        {
            string postData   = "";
            string encodeName = Encode(koreanName);

            if (koreanName.Contains("-"))
            {
                encodeName = Encode(koreanName.Split('-')[1]);
            }

            if (times == 0)
            {
                postData = string.Format("kind=&ef_std_cd_grnt_dt_from=&ef_std_cd_grnt_dt_to=&secuGubun=01&lst_yn1=Y&els_dls_all=on&els_dls1=els&els_dls2=dls&so_gb_all=on&so_gb1=s&so_gb2=o&jp_gb_all=on&jp_gb1=c&jp_gb2=t&jp_gb3=r&jp_gb4=i&hg_gb_all=on&hg_gb1=h&hg_gb2=g&tg_gb_all=on&tg_gb1=x&tg_gb2=z&df_gb_all=on&df_gb1=df1&df_gb2=df2&df_gb3=df3&df_gb4=df4&df_gb5=df5&df_gb6=df6&df_gb7=df7&cb_search_column=co_nm&ef_key_word={0}&ef_iss_inst_cd=&ef_isu_nm={0}%BA%B8%C5%EB%C1%D6&ef_iss_dt_from=&ef_iss_dt_to=&ef_lst_dt_from=&ef_lst_dt_to=", encodeName);
            }
            else if (times == 1)
            {
                postData = string.Format("kind=&ef_std_cd_grnt_dt_from=&ef_std_cd_grnt_dt_to=&secuGubun=01&lst_yn1=Y&els_dls_all=on&els_dls1=els&els_dls2=dls&so_gb_all=on&so_gb1=s&so_gb2=o&jp_gb_all=on&jp_gb1=c&jp_gb2=t&jp_gb3=r&jp_gb4=i&hg_gb_all=on&hg_gb1=h&hg_gb2=g&tg_gb_all=on&tg_gb1=x&tg_gb2=z&df_gb_all=on&df_gb1=df1&df_gb2=df2&df_gb3=df3&df_gb4=df4&df_gb5=df5&df_gb6=df6&df_gb7=df7&cb_search_column=co_nm&ef_key_word={0}&ef_iss_inst_cd=&ef_isu_nm=%BA%B8%C5%EB%C1%D6&ef_iss_dt_from=&ef_iss_dt_to=&ef_lst_dt_from=&ef_lst_dt_to=", encodeName);
            }
            string         uri     = "http://isin.krx.co.kr/jsp/realBoard01.jsp";
            HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;

            request.Timeout     = 100000;
            request.UserAgent   = "Mozilla/5.0 (Windows NT 5.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2";
            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Referer     = "http://isin.krx.co.kr/jsp/BA_LT113.jsp";
            request.Headers.Add("Accept-Encoding: gzip,deflate,sdch");

            string pageSource = null;
            int    retries    = 3;

            while (pageSource == null && retries-- > 0)
            {
                try
                {
                    pageSource = WebClientUtil.GetDynamicPageSource(request, postData, Encoding.GetEncoding("EUC-KR"));
                }
                catch
                {
                    System.Threading.Thread.Sleep(5000);
                }
            }
            string       isin = "";
            HtmlDocument doc  = new HtmlDocument();

            doc.LoadHtml(pageSource);

            HtmlNodeCollection trs = null;

            try
            {
                trs = doc.DocumentNode.SelectNodes("/html[1]/body[1]/table[1]/tr[2]/td[1]/table[1]/tr");
            }
            catch
            {
                string msg = "Error found in searching new underlying record found for " + koreanName;
                //Logger.Log(msg, Logger.LogType.Error);
                isin = InputISIN.Prompt(koreanName, "Underlying Name");
            }
            //not found
            if (trs == null || trs.Count > 2)
            {
                isin = InputISIN.Prompt(koreanName, "Underlying Name");
            }
            else if (trs.Count == 1)
            {
                isin = times == 0 ? GetIsinByName(koreanName, 1) : InputISIN.Prompt(koreanName, "Underlying Name");
            }
            //find only one record
            else if (trs.Count == 2)
            {
                HtmlNode           tr  = trs[1];
                HtmlNodeCollection tds = tr.SelectNodes("./td");
                isin = tds[1].InnerText.Trim();
            }
            return(isin);
        }