Esempio n. 1
0
        private ArrayList GetOptionChainFromDocument(HtmlDocument doc, SymbolSet.SymbolTableRow tck, DateTime expdate)
        {
            // locate table of "Open Int" element
            HtmlElement table_elem = WebForm.LocateParentElement(doc, "Open Int", 0, "TABLE");

            if (table_elem == null)
            {
                return(null);
            }

            // get quote table
            XmlDocument xml = cap.ConvertHtmlToXml(table_elem.OuterHtml);

            if (xml == null)
            {
                return(null);
            }

            // create options array list
            ArrayList options_list = new ArrayList();

            for (int i = 2; ; i++)
            {
                XmlNode nd, row_nd = prs.GetXmlNodeByPath(xml.FirstChild, @"TBODY\TR(" + i.ToString() + ")");
                if (row_nd == null)
                {
                    break;
                }

                // get strike
                nd = prs.GetXmlNodeByPath(row_nd, @"TD(9)");
                double strike = double.NaN;
                if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
                {
                    try
                    {
                        strike = Convert.ToDouble(System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim(), ci);
                    }
                    catch { }
                }
                if (double.IsNaN(strike))
                {
                    continue;
                }

                for (int j = 0; j <= 9; j += 9)
                {
                    // create new option
                    Option option = new Option();

                    // type
                    option.type = (j == 0) ? "Call" : "Put";

                    // strike
                    option.strike = strike;

                    // underlying
                    option.stock = tck.Symbol;

                    // update time stamp
                    option.update_timestamp = DateTime.Now;

                    // exipration date
                    nd = prs.GetXmlNodeByPath(row_nd, @"TD(" + (j + 1).ToString() + ")");
                    if (nd == null || string.IsNullOrEmpty(nd.InnerText))
                    {
                        break;
                    }
                    string[] split = nd.InnerText.Replace(",", "").Split(' ');
                    option.expiration = expdate;
                    DateTime.TryParse(split[1] + "-" + split[0] + "-" + split[2], ci, DateTimeStyles.None, out option.expiration);

                    // symbol
                    option.symbol = string.Format(".{0}{1:yyMMdd}{2}{3:00000000}", tck.Symbol.TrimStart(new char[] { '^' }), option.expiration, option.type[0], option.strike * 1000);

                    // get last price
                    nd = prs.GetXmlNodeByPath(row_nd, @"TD(" + (j + 2).ToString() + ")");
                    option.price.last = double.NaN;
                    if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
                    {
                        try
                        {
                            string stmp = System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim();
                            if (!string.IsNullOrEmpty(stmp))
                            {
                                option.price.last = Convert.ToDouble(stmp, ci);
                            }
                        }
                        catch { }
                    }

                    // get price change
                    nd = prs.GetXmlNodeByPath(row_nd, @"TD(" + (j + 3).ToString() + ")");
                    option.price.change = double.NaN;
                    if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
                    {
                        try
                        {
                            string stmp = System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim();
                            if (!string.IsNullOrEmpty(stmp))
                            {
                                option.price.change = Convert.ToDouble(stmp, ci);
                            }
                        }
                        catch { }
                    }

                    // get bid price
                    nd = prs.GetXmlNodeByPath(row_nd, @"TD(" + (j + 4).ToString() + ")");
                    option.price.bid = double.NaN;
                    if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
                    {
                        try
                        {
                            string stmp = System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim();
                            if (!string.IsNullOrEmpty(stmp))
                            {
                                option.price.bid = Convert.ToDouble(stmp, ci);
                            }
                        }
                        catch { }
                    }

                    // get ask price
                    nd = prs.GetXmlNodeByPath(row_nd, @"TD(" + (j + 5).ToString() + ")");
                    option.price.ask = double.NaN;
                    if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
                    {
                        try
                        {
                            string stmp = System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim();
                            if (!string.IsNullOrEmpty(stmp))
                            {
                                option.price.ask = Convert.ToDouble(stmp, ci);
                            }
                        }
                        catch { }
                    }

                    // get volume
                    nd = prs.GetXmlNodeByPath(row_nd, @"TD(" + (j + 6).ToString() + ")");
                    option.volume.total = 0;
                    if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
                    {
                        try
                        {
                            string stmp = System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim();
                            if (!string.IsNullOrEmpty(stmp))
                            {
                                option.volume.total = Convert.ToInt32(stmp, ci);
                            }
                        }
                        catch { }
                    }

                    // get open interest
                    nd = prs.GetXmlNodeByPath(row_nd, @"TD(" + (j + 7).ToString() + ")");
                    option.open_int = 0;
                    if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
                    {
                        try
                        {
                            string stmp = System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim();
                            if (!string.IsNullOrEmpty(stmp))
                            {
                                option.open_int = Convert.ToInt32(stmp, ci);
                            }
                        }
                        catch { }
                    }

                    // add option to option-list
                    options_list.Add(option);
                }
            }

            return(options_list);
        }
Esempio n. 2
0
        private Quote GetQuoteFromDocument(HtmlDocument doc, SymbolSet.SymbolTableRow tck)
        {
            // locate table of "Last Sale" element
            HtmlElement table_elem = WebForm.LocateParentElement(doc, "Last Sale", 0, "TABLE");

            if (table_elem == null)
            {
                return(null);
            }

            // get quote table
            XmlDocument xml = cap.ConvertHtmlToXml(table_elem.OuterHtml);

            if (xml == null)
            {
                return(null);
            }

            XmlNode nd, row_nd = prs.GetXmlNodeByPath(xml.FirstChild, @"TBODY\TR(2)");

            if (row_nd == null)
            {
                return(null);
            }

            // create qutote
            Quote quote = new Quote();

            // get date and time
            quote.update_timestamp = DateTime.Now;

            // get underlying symbol
            quote.stock = tck.Symbol;

            // get underlying name
            nd = prs.GetXmlNodeByPath(row_nd, @"TD(1)");
            if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
            {
                quote.name = System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim().Trim();
            }
            else
            {
                quote.name = tck.Name;
            }

            // get underlying last price
            nd = prs.GetXmlNodeByPath(row_nd, @"TD(4)");
            quote.price.last = double.NaN;
            if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
            {
                try
                {
                    quote.price.last = Convert.ToDouble(System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim(), ci);
                }
                catch { }
            }

            // get underlying price change
            nd = prs.GetXmlNodeByPath(row_nd, @"TD(5)\SPAN\#text");
            quote.price.change = double.NaN;
            if (nd != null && !string.IsNullOrEmpty(nd.InnerText))
            {
                try
                {
                    quote.price.change = Convert.ToDouble(System.Web.HttpUtility.HtmlDecode(nd.InnerText).Trim(), ci);
                }
                catch { }
            }

            // get open price
            quote.price.open = quote.price.last - quote.price.change;

            // set unsupported data to NaN
            quote.price.low    = double.NaN;
            quote.price.high   = double.NaN;
            quote.price.bid    = double.NaN;
            quote.price.ask    = double.NaN;
            quote.volume.total = double.NaN;

            return(quote);
        }