internal QuoteOptionsData(string symb, QuoteOptionType typ, double strike, double last, double cng, double b, double a, int vol, int interest) { this.Symbol = symb; this.Type = typ; this.StrikePrice = strike; this.LastPrice = last; this.Change = cng; this.Bid = b; this.Ask = a; this.Volume = vol; this.OpenInterest = interest; }
/// <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(XElement 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 (XAttribute 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 (XElement 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); } }