/// <summary> /// Gets or sets the value of a specfic property /// </summary> /// <param name="prp">Gets or sets the property you want to get or set</param> /// <value></value> /// <returns></returns> /// <remarks></remarks> public object this[QuoteProperty prp] { get { return(mValues[(int)prp]); } set { if (value != null) { double t = 0; System.DateTime dt; long l = 0; switch (prp) { case QuoteProperty.Symbol: base.SetID(value.ToString()); break; case QuoteProperty.LastTradePriceOnly: if (double.TryParse(value.ToString(), out t)) { base.LastTradePriceOnly = t; } break; case QuoteProperty.LastTradeDate: if (System.DateTime.TryParse(value.ToString(), out dt)) { base.LastTradeDate = dt; } break; case QuoteProperty.LastTradeTime: if (System.DateTime.TryParse(value.ToString(), out dt)) { base.LastTradeTime = dt; } break; case QuoteProperty.Change: if (double.TryParse(value.ToString(), out t)) { base.Change = t; } break; case QuoteProperty.Volume: if (long.TryParse(value.ToString(), out l)) { base.Volume = l; } break; case QuoteProperty.Name: base.Name = value.ToString(); break; } } mValues[(int)prp] = value; } }
public void DownloadCompanyFundamentals() { //Parameters IEnumerable <QuoteProperty> properties = new QuoteProperty[] { QuoteProperty.Symbol, QuoteProperty.Name, QuoteProperty.BidRealtime, QuoteProperty.EPSEstimateCurrentYear, QuoteProperty.EPSEstimateNextYear, QuoteProperty.PERatioRealtime, QuoteProperty.ShortRatio, QuoteProperty.PEGRatio, QuoteProperty.OneyrTargetPrice, QuoteProperty.MarketCapRealtime, QuoteProperty.LastTradePriceOnly, QuoteProperty.YearHigh, QuoteProperty.PreviousClose, }; //Download QuotesDownload dl = new QuotesDownload(); var resp = dl.Download(ids, properties); //Response/Result if (resp.Connection.State == MaasOne.Base.ConnectionState.Success) { string id; string Symbol; string name; double bidRealtime; double ePSEstimateCurrentYear; double epsNextYear; double peg; double oneYearTargetprice; double lastPrice; double yearHigh; double previousClose; foreach (var qd in resp.Result.Items) { id = qd.ID; Symbol = qd[QuoteProperty.Symbol].ToString(); name = qd.Name; bidRealtime = Convert.ToDouble(qd[QuoteProperty.BidRealtime]); double.TryParse(qd[QuoteProperty.EPSEstimateCurrentYear].ToString(), out ePSEstimateCurrentYear); double.TryParse(qd[QuoteProperty.EPSEstimateNextYear].ToString(), out epsNextYear); double.TryParse(qd[QuoteProperty.PEGRatio].ToString(), out peg); double.TryParse(qd[QuoteProperty.OneyrTargetPrice].ToString(), out oneYearTargetprice); lastPrice = qd.LastTradePriceOnly; yearHigh = Convert.ToDouble(qd[QuoteProperty.YearHigh]); previousClose = Convert.ToDouble(qd[QuoteProperty.PreviousClose]); Console.WriteLine("Symbol {0}, lastPrice {1:C}, OneYearTarget {2:C} , EPSNextYear {3:C}, Growth {4:p2}" , Symbol, lastPrice, oneYearTargetprice, epsNextYear, (epsNextYear / ePSEstimateCurrentYear)); } } }
public void SortBy(QuoteProperty property) { try { base.Items = base.Items.OrderBy(item => ((YahooQuotesData)item)[property] ?? double.MinValue).ToArray(); } catch (Exception ex) { } }
private static object QuoteStringToObject(string value, QuoteProperty prp, System.Globalization.CultureInfo culture) { object o = MyHelper.StringToObject(value, culture); if (prp == QuoteProperty.Name && o is Array && ((Array)o).Length > 0) { Array arr = (Array)o; string s = ""; for (int i = 0; i < arr.Length; i++) { s += arr.GetValue(i).ToString(); if (i != arr.Length - 1) { s += " - "; } } return(s); } else { return(o); } }
public static string CsvQuotePropertyTags(QuoteProperty[] properties) { System.Text.StringBuilder symbols = new System.Text.StringBuilder(); if (properties != null && properties.Length > 0) { foreach (QuoteProperty qp in properties) { switch (qp) { case QuoteProperty.Ask: symbols.Append("a0"); break; case QuoteProperty.AverageDailyVolume: symbols.Append("a2"); break; case QuoteProperty.AskSize: symbols.Append("a5"); break; case QuoteProperty.Bid: symbols.Append("b0"); break; case QuoteProperty.AskRealtime: symbols.Append("b2"); break; case QuoteProperty.BidRealtime: symbols.Append("b3"); break; case QuoteProperty.BookValuePerShare: symbols.Append("b4"); break; case QuoteProperty.BidSize: symbols.Append("b6"); break; case QuoteProperty.Change_ChangeInPercent: symbols.Append('c'); break; case QuoteProperty.Change: symbols.Append("c1"); break; case QuoteProperty.Commission: symbols.Append("c3"); break; case QuoteProperty.Currency: symbols.Append("c4"); break; case QuoteProperty.ChangeRealtime: symbols.Append("c6"); break; case QuoteProperty.AfterHoursChangeRealtime: symbols.Append("c8"); break; case QuoteProperty.TrailingAnnualDividendYield: symbols.Append("d0"); break; case QuoteProperty.LastTradeDate: symbols.Append("d1"); break; case QuoteProperty.TradeDate: symbols.Append("d2"); break; case QuoteProperty.DilutedEPS: symbols.Append("e0"); break; case QuoteProperty.EPSEstimateCurrentYear: symbols.Append("e7"); break; case QuoteProperty.EPSEstimateNextYear: symbols.Append("e8"); break; case QuoteProperty.EPSEstimateNextQuarter: symbols.Append("e9"); break; case QuoteProperty.TradeLinksAdditional: symbols.Append("f0"); break; case QuoteProperty.SharesFloat: symbols.Append("f6"); break; case QuoteProperty.DaysLow: symbols.Append("g0"); break; case QuoteProperty.HoldingsGainPercent: symbols.Append("g1"); break; case QuoteProperty.AnnualizedGain: symbols.Append("g3"); break; case QuoteProperty.HoldingsGain: symbols.Append("g4"); break; case QuoteProperty.HoldingsGainPercentRealtime: symbols.Append("g5"); break; case QuoteProperty.HoldingsGainRealtime: symbols.Append("g6"); break; case QuoteProperty.DaysHigh: symbols.Append("h0"); break; case QuoteProperty.MoreInfo: symbols.Append('i'); break; case QuoteProperty.OrderBookRealtime: symbols.Append("i5"); break; case QuoteProperty.YearLow: symbols.Append("j0"); break; case QuoteProperty.MarketCapitalization: symbols.Append("j1"); break; case QuoteProperty.SharesOutstanding: symbols.Append("j2"); break; case QuoteProperty.MarketCapRealtime: symbols.Append("j3"); break; case QuoteProperty.EBITDA: symbols.Append("j4"); break; case QuoteProperty.ChangeFromYearLow: symbols.Append("j5"); break; case QuoteProperty.PercentChangeFromYearLow: symbols.Append("j6"); break; case QuoteProperty.YearHigh: symbols.Append("k0"); break; case QuoteProperty.LastTradeRealtimeWithTime: symbols.Append("k1"); break; case QuoteProperty.ChangeInPercentRealtime: symbols.Append("k2"); break; case QuoteProperty.LastTradeSize: symbols.Append("k3"); break; case QuoteProperty.ChangeFromYearHigh: symbols.Append("k4"); break; case QuoteProperty.ChangeInPercentFromYearHigh: symbols.Append("k5"); break; case QuoteProperty.LastTradeWithTime: symbols.Append("l0"); break; case QuoteProperty.LastTradePriceOnly: symbols.Append("l1"); break; case QuoteProperty.HighLimit: symbols.Append("l2"); break; case QuoteProperty.LowLimit: symbols.Append("l3"); break; case QuoteProperty.DaysRange: symbols.Append('m'); break; case QuoteProperty.DaysRangeRealtime: symbols.Append("m2"); break; case QuoteProperty.FiftydayMovingAverage: symbols.Append("m3"); break; case QuoteProperty.TwoHundreddayMovingAverage: symbols.Append("m4"); break; case QuoteProperty.ChangeFromTwoHundreddayMovingAverage: symbols.Append("m5"); break; case QuoteProperty.PercentChangeFromTwoHundreddayMovingAverage: symbols.Append("m6"); break; case QuoteProperty.ChangeFromFiftydayMovingAverage: symbols.Append("m7"); break; case QuoteProperty.PercentChangeFromFiftydayMovingAverage: symbols.Append("m8"); break; case QuoteProperty.Name: symbols.Append("n0"); break; case QuoteProperty.Notes: symbols.Append("n4"); break; case QuoteProperty.Open: symbols.Append("o0"); break; case QuoteProperty.PreviousClose: symbols.Append("p0"); break; case QuoteProperty.PricePaid: symbols.Append("p1"); break; case QuoteProperty.ChangeInPercent: symbols.Append("p2"); break; case QuoteProperty.PriceSales: symbols.Append("p5"); break; case QuoteProperty.PriceBook: symbols.Append("p6"); break; case QuoteProperty.ExDividendDate: symbols.Append("q0"); break; case QuoteProperty.PERatio: symbols.Append("r0"); break; case QuoteProperty.DividendPayDate: symbols.Append("r1"); break; case QuoteProperty.PERatioRealtime: symbols.Append("r2"); break; case QuoteProperty.PEGRatio: symbols.Append("r5"); break; case QuoteProperty.PriceEPSEstimateCurrentYear: symbols.Append("r6"); break; case QuoteProperty.PriceEPSEstimateNextYear: symbols.Append("r7"); break; case QuoteProperty.Symbol: symbols.Append("s0"); break; case QuoteProperty.SharesOwned: symbols.Append("s1"); break; case QuoteProperty.Revenue: symbols.Append("s6"); break; case QuoteProperty.ShortRatio: symbols.Append("s7"); break; case QuoteProperty.LastTradeTime: symbols.Append("t1"); break; case QuoteProperty.TradeLinks: symbols.Append("t6"); break; case QuoteProperty.TickerTrend: symbols.Append("t7"); break; case QuoteProperty.OneyrTargetPrice: symbols.Append("t8"); break; case QuoteProperty.Volume: symbols.Append("v0"); break; case QuoteProperty.HoldingsValue: symbols.Append("v1"); break; case QuoteProperty.HoldingsValueRealtime: symbols.Append("v7"); break; case QuoteProperty.YearRange: symbols.Append("w0"); break; case QuoteProperty.DaysValueChange: symbols.Append("w1"); break; case QuoteProperty.DaysValueChangeRealtime: symbols.Append("w4"); break; case QuoteProperty.StockExchange: symbols.Append("x0"); break; case QuoteProperty.TrailingAnnualDividendYieldInPercent: symbols.Append("y0"); break; } } } return symbols.ToString(); }
public object Values(QuoteProperty prp) { return(this[prp]); }
private static object QuoteStringToObject(string value, QuoteProperty prp, System.Globalization.CultureInfo culture) { object o = MyHelper.StringToObject(value, culture); if (prp == QuoteProperty.Name && o is Array && ((Array)o).Length > 0) { Array arr = (Array)o; string s = ""; for (int i = 0; i < arr.Length; i++) { s += arr.GetValue(i).ToString(); if (i != arr.Length - 1) { s += " - "; } } return s; } else { return o; } }
private static string[] CsvNewRowItems(string[] oldItems, QuoteProperty[] properties, KeyValuePair<QuoteProperty, int>[] multipleItemProperties) { System.Globalization.CultureInfo convCulture = new System.Globalization.CultureInfo("en-US"); List<string> newRowItems = new List<string>(); int itemsCount = properties.Length; foreach (KeyValuePair<QuoteProperty, int> q in multipleItemProperties) { itemsCount += q.Value - 1; } if (itemsCount == oldItems.Length) { int actualIndex = 0; foreach (QuoteProperty qp in properties) { Nullable<KeyValuePair<QuoteProperty, int>> alternatProperty = null; foreach (KeyValuePair<QuoteProperty, int> q in multipleItemProperties) { if (q.Key == qp) { alternatProperty = q; break; // TODO: might not be correct. Was : Exit For } } if (!alternatProperty.HasValue) { newRowItems.Add(oldItems[actualIndex]); } else { string newRowItem = string.Empty; for (int i = actualIndex; i <= (actualIndex + alternatProperty.Value.Value - 1); i++) { int @int = 0; if (int.TryParse(oldItems[i], System.Globalization.NumberStyles.Integer, convCulture, out @int) && (oldItems[i] == @int.ToString() || oldItems[i] == "000")) { newRowItem += oldItems[i]; } else { newRowItem = string.Empty; break; // TODO: might not be correct. Was : Exit For } } if (newRowItem != string.Empty) { newRowItems.Add(newRowItem); actualIndex += alternatProperty.Value.Value - 1; } } actualIndex += 1; } } return newRowItems.ToArray(); }
private static QuotesData CsvArrayToQuoteData(string[] rowItems, QuoteProperty[] properties, System.Globalization.CultureInfo culture) { if (rowItems.Length > 0) { QuotesData quote = null; if (rowItems.Length == properties.Length) { quote = new QuotesData(); for (int i = 0; i <= properties.Length - 1; i++) { quote[properties[i]] = QuoteStringToObject(rowItems[i], properties[i], culture); } } else { if (rowItems.Length > 1) { List<QuoteProperty> alternateProperties = new List<QuoteProperty>(); foreach (QuoteProperty qp in properties) { foreach (QuoteProperty q in mAlternateQuoteProperties) { if (qp == q) { alternateProperties.Add(qp); break; } } } if (alternateProperties.Count > 0) { List<KeyValuePair<QuoteProperty, int>[]> lst = new List<KeyValuePair<QuoteProperty, int>[]>(); int[][] permutations = MaxThreePerm(alternateProperties.Count, Math.Min(rowItems.Length - properties.Length + 1, 3)); foreach (int[] perm in permutations) { List<KeyValuePair<QuoteProperty, int>> lst2 = new List<KeyValuePair<QuoteProperty, int>>(); for (int i = 0; i <= alternateProperties.Count - 1; i++) { lst2.Add(new KeyValuePair<QuoteProperty, int>(alternateProperties[i], perm[i])); } lst.Add(lst2.ToArray()); } foreach (KeyValuePair<QuoteProperty, int>[] combination in lst) { String[] newRowItems = CsvNewRowItems(rowItems, properties, combination); try { if (newRowItems.Length > 0) { quote = new QuotesData(); for (int i = 0; i <= properties.Length - 1; i++) { quote[properties[i]] = QuoteStringToObject(rowItems[i], properties[i], culture); } break; } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } } } } } return quote; } else { return null; } }
internal static QuotesData[] ToQuotesData(string csvText, char delimiter, QuoteProperty[] properties, System.Globalization.CultureInfo culture, bool hasHeader = false) { List<QuotesData> quotes = new List<QuotesData>(); if (csvText != string.Empty & culture != null & (properties != null && properties.Length > 0)) { if (properties.Length > 0) { string[][] table = MyHelper.CsvTextToStringTable(csvText, delimiter); int start = 0; if (hasHeader) start = 1; if (table.Length > 0) { if (!(table[0].Length == properties.Length)) { String[][] semicolTable = MyHelper.CsvTextToStringTable(csvText, Convert.ToChar((delimiter == ';' ? ',' : ';'))); if (semicolTable[0].Length == properties.Length) { table = semicolTable; } } if (table.Length > 0 && table.Length > start) { for (int i = start; i <= table.Length - 1; i++) { QuotesData qd = CsvArrayToQuoteData(table[i], properties, culture); if (qd != null) quotes.Add(qd); } } } } } return quotes.ToArray(); }