예제 #1
0
        /// <summary>
        /// Tries to read a QuoteOption from XML
        /// </summary>
        /// <param name="node">The XML node of QuoteOption</param>
        /// <param name="culture">The used culture for formating dates and numbers. If parameter value is null/Nothing, default Culture will be used.</param>
        /// <returns>The converted quote data or Nothing</returns>
        /// <remarks></remarks>
        public static QuoteOptionsData ToQuoteOption(XParseElement node, System.Globalization.CultureInfo culture = null)
        {
            if (node != null && node.Name.LocalName.ToLower() == "option")
            {
                System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
                if (culture != null)
                {
                    ci = culture;
                }
                string symbol = string.Empty;
                string t      = string.Empty;
                foreach (XParseAttribute att in node.Attributes())
                {
                    switch (att.Name.LocalName)
                    {
                    case FinanceHelper.NameOptionSymbol:
                        symbol = att.Value;
                        break;

                    case "type":
                        t = att.Value;
                        break;
                    }
                }
                QuoteOptionType type = QuoteOptionType.Call;
                if (t.ToLower() == "p")
                {
                    type = QuoteOptionType.Put;
                }
                double strikePrice = 0;
                double lastPrice   = 0;
                double change      = 0;
                double bid         = 0;
                double ask         = 0;
                int    volume      = 0;
                int    openInt     = 0;
                foreach (XParseElement propertyNode in node.Elements())
                {
                    switch (propertyNode.Name.LocalName)
                    {
                    case FinanceHelper.NameOptionStrikePrice:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out strikePrice);
                        break;

                    case FinanceHelper.NameOptionLastPrice:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out lastPrice);
                        break;

                    case FinanceHelper.NameOptionChange:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out change);
                        break;

                    case FinanceHelper.NameOptionChangeDir:
                        if (propertyNode.Value == "Down")
                        {
                            change *= -1;
                        }
                        break;

                    case FinanceHelper.NameOptionBid:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out bid);
                        break;

                    case FinanceHelper.NameOptionAsk:
                        double.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Currency, ci, out ask);
                        break;

                    case FinanceHelper.NameOptionVolume:
                        int.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Integer, ci, out volume);
                        break;

                    case FinanceHelper.NameOptionOpenInterest:
                        int.TryParse(propertyNode.Value, System.Globalization.NumberStyles.Integer, ci, out openInt);
                        break;
                    }
                }
                return(new QuoteOptionsData(symbol, type, strikePrice, lastPrice, change, bid, ask, volume, openInt));
            }
            else
            {
                return(null);
            }
        }