Ejemplo n.º 1
0
        // get stock latest options chain
        public ArrayList GetOptionsChain(string ticker)
        {
            // make sure we are connected
            if (!Connect)
            {
                Connect = true;
                if (!Connect)
                {
                    return(null);
                }
            }

            // correct symbol
            ticker = CorrectSymbol(ticker);

            // get end-of-day option chain
            //ArrayList list = GetEndOfDayOptionChain(ticker);

            // get four-months option chain
            ArrayList list = GetToMonthOptionChain(ticker);

            // construct list of all options
            List <string> sym_list = new List <string>();

            foreach (Option option in list)
            {
                sym_list.Add(option.symbol.Replace(".", ""));
            }

            // get tick-list and mini-book list
            Dictionary <string, TradeZone.Tick>     ord_list = data_center.GetQuoteTick(sym_list);
            Dictionary <string, TradeZone.Minibook> mnb_list = data_center.GetQuoteMiniBook(sym_list);

            if (ord_list == null || mnb_list == null)
            {
                return(null);
            }

            // options with no market data list
            ArrayList sym_withnodata = new ArrayList();

            foreach (Option option in list)
            {
                try
                {
                    bool with_data = false;

                    if (mnb_list.ContainsKey(option.symbol))
                    {
                        TradeZone.Minibook minibook = mnb_list[option.symbol];

                        option.price.ask = minibook.Items[0].BestAskPrice;
                        option.price.bid = minibook.Items[0].BestAskPrice;
                        with_data        = true;
                    }
                    else
                    {
                        option.price.ask = double.NaN;
                        option.price.bid = double.NaN;
                    }

                    if (ord_list.ContainsKey(option.symbol))
                    {
                        TradeZone.Tick tick = ord_list[option.symbol];

                        option.price.last   = tick.Last;
                        option.price.change = tick.Last - tick.Open;

                        option.update_timestamp = tick.Timestamp;
                        option.volume.total     = (double)tick.TradeVolume;
                        option.open_int         = (int)tick.TotalVolume;
                        with_data = true;
                    }
                    else
                    {
                        option.price.last       = double.NaN;
                        option.price.change     = double.NaN;
                        option.update_timestamp = DateTime.Now;
                        option.volume.total     = 0;
                    }

                    if (!with_data)
                    {
                        sym_withnodata.Add(option);
                    }
                }
                catch { }
            }

            try
            {
                if (!config.ContainsKey("HideOptionsWithNoMarket") || bool.Parse(config["HideOptionsWithNoMarket"]))
                {
                    foreach (Option option in sym_withnodata)
                    {
                        list.Remove(option);
                    }
                }
            }
            catch { }

            return(list);
        }
Ejemplo n.º 2
0
        // get stock latest quote
        public Quote GetQuote(string ticker)
        {
            // make sure we are connected
            if (!Connect)
            {
                Connect = true;
                if (!Connect)
                {
                    return(null);
                }
            }

            // correct symbol
            ticker = CorrectSymbol(ticker);

            // trade-zone ticker
            string ticker_tz = ticker.TrimStart(new char[] { '^' });

            // create one symbol list
            List <string> sym_list = new List <string>();

            sym_list.Add(ticker_tz);

            // get tick-list and mini-book list
            Dictionary <string, TradeZone.Tick>     ord_list = data_center.GetQuoteTick(sym_list);
            Dictionary <string, TradeZone.Minibook> mnb_list = data_center.GetQuoteMiniBook(sym_list);

            if (ord_list == null || mnb_list == null)
            {
                return(null);
            }

            // get symbol lookup
            string sym_lookup = data_center.GetSymbolsStream(ticker_tz);

            if (ord_list.ContainsKey(ticker_tz))
            {
                TradeZone.Tick tick = ord_list[ticker_tz];

                Quote quote = new Quote();

                quote.name  = tick.Stock;
                quote.stock = ticker;

                if (sym_lookup != null)
                {
                    string[] sym_split = sym_lookup.Split(new char[] { ';' });
                    if (sym_split.Length > 1)
                    {
                        quote.name = sym_split[1].Substring(0, 1).ToUpper() + sym_split[1].Substring(1).ToLower();
                    }
                }

                quote.price.open   = tick.Open;
                quote.price.last   = tick.Last;
                quote.price.change = quote.price.last - quote.price.open;
                quote.price.high   = tick.High;
                quote.price.low    = tick.Low;

                if (mnb_list.ContainsKey(ticker_tz))
                {
                    TradeZone.Minibook minibook = mnb_list[ticker_tz];

                    if (minibook != null && minibook.Items.Count > 0)
                    {
                        quote.price.ask = minibook.Items[0].BestAskPrice;
                        quote.price.bid = minibook.Items[0].BestBidPrice;
                    }
                }

                quote.update_timestamp = tick.Timestamp;
                quote.volume.total     = (double)tick.TradeVolume;

                // save quote in quote dict
                quote_dict[quote.stock] = quote;
                return(quote);
            }

            return(null);
        }