protected override MarketQuotesResult ConvertResult(YahooManaged.Base.ConnectionInfo connInfo, System.IO.Stream stream, YahooManaged.Base.SettingsBase settings)
        {
            System.Globalization.CultureInfo ci = FinanceHelper.DefaultYqlCulture;

            string text      = MyHelper.StreamToString(stream, ((MarketQuotesDownloadSettings)settings).TextEncoding);
            char   delimiter = ',';

            string[][] table = MyHelper.CsvTextToStringTable(text, delimiter);

            List <MarketQuotesData> lst = new List <MarketQuotesData>();

            if (table.Length > 1)
            {
                for (int i = 1; i <= table.Length - 1; i++)
                {
                    if (table[i].Length == 10)
                    {
                        MarketQuotesData quote = new MarketQuotesData();
                        quote.Name = table[i][0];
                        double t1;
                        if (double.TryParse(table[i][1], System.Globalization.NumberStyles.Any, ci, out t1))
                        {
                            quote.OneDayPriceChangePercent = t1;
                        }
                        string mktcap = table[i][2];
                        if (mktcap != "NA" & mktcap != string.Empty & mktcap.Length > 1)
                        {
                            double value = 0;
                            double.TryParse(mktcap.Substring(0, mktcap.Length - 1), System.Globalization.NumberStyles.Any, ci, out value);
                            quote.MarketCapitalizationInMillion = value * FinanceHelper.GetStringMillionFactor(mktcap);
                        }
                        double t2;
                        double t3;
                        double t4;
                        double t5;
                        double t6;
                        double t7;
                        double t8;
                        if (double.TryParse(table[i][3], System.Globalization.NumberStyles.Any, ci, out t2))
                        {
                            quote.PriceEarningsRatio = t2;
                        }
                        if (double.TryParse(table[i][4], System.Globalization.NumberStyles.Any, ci, out t3))
                        {
                            quote.ReturnOnEquityPercent = t3;
                        }
                        if (double.TryParse(table[i][5], System.Globalization.NumberStyles.Any, ci, out t4))
                        {
                            quote.DividendYieldPercent = t4;
                        }
                        if (double.TryParse(table[i][6], System.Globalization.NumberStyles.Any, ci, out t5))
                        {
                            quote.LongTermDeptToEquity = t5;
                        }
                        if (double.TryParse(table[i][7], System.Globalization.NumberStyles.Any, ci, out t6))
                        {
                            quote.PriceToBookValue = t6;
                        }
                        if (double.TryParse(table[i][8], System.Globalization.NumberStyles.Any, ci, out t7))
                        {
                            quote.NetProfitMarginPercent = t7;
                        }
                        if (double.TryParse(table[i][9], System.Globalization.NumberStyles.Any, ci, out t8))
                        {
                            quote.PriceToFreeCashFlow = t8;
                        }
                        lst.Add(quote);
                    }
                }
            }

            return(new MarketQuotesResult(lst.ToArray()));
        }
Пример #2
0
        public static MarketQuotesData[] ToMarketQuotesData(string csv, System.Globalization.CultureInfo culture = null)
        {
            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CurrentCulture;
            if (culture != null)
            {
                ci = culture;
            }
            char delimiter = ',';

            string[][] table            = MyHelper.CsvTextToStringTable(csv, delimiter);
            List <MarketQuotesData> lst = new List <MarketQuotesData>();

            if (table.Length > 1)
            {
                for (int i = 1; i <= table.Length - 1; i++)
                {
                    if (table[i].Length == 10)
                    {
                        MarketQuotesData quote = new MarketQuotesData();
                        quote.Name = table[i][0];

                        double t1;
                        double t2;
                        double t3;
                        double t4;
                        double t5;
                        double t6;
                        double t7;
                        double t8;

                        if (double.TryParse(table[i][1], System.Globalization.NumberStyles.Any, ci, out t1))
                        {
                            quote.OneDayPriceChangePercent = t1;
                        }
                        string mktcap = table[i][2];
                        if (mktcap != "NA" & mktcap != string.Empty & mktcap.Length > 1)
                        {
                            double value = 0;
                            double.TryParse(mktcap.Substring(0, mktcap.Length - 1), System.Globalization.NumberStyles.Any, ci, out value);
                            quote.MarketCapitalizationInMillion = value * FinanceHelper.GetStringMillionFactor(mktcap);
                        }
                        if (double.TryParse(table[i][3], System.Globalization.NumberStyles.Any, ci, out t2))
                        {
                            quote.PriceEarningsRatio = t2;
                        }
                        if (double.TryParse(table[i][4], System.Globalization.NumberStyles.Any, ci, out t3))
                        {
                            quote.ReturnOnEquityPercent = t3;
                        }
                        if (double.TryParse(table[i][5], System.Globalization.NumberStyles.Any, ci, out t4))
                        {
                            quote.DividendYieldPercent = t4;
                        }
                        if (double.TryParse(table[i][6], System.Globalization.NumberStyles.Any, ci, out t5))
                        {
                            quote.LongTermDeptToEquity = t5;
                        }
                        if (double.TryParse(table[i][7], System.Globalization.NumberStyles.Any, ci, out t6))
                        {
                            quote.PriceToBookValue = t6;
                        }
                        if (double.TryParse(table[i][8], System.Globalization.NumberStyles.Any, ci, out t7))
                        {
                            quote.NetProfitMarginPercent = t7;
                        }
                        if (double.TryParse(table[i][9], System.Globalization.NumberStyles.Any, ci, out t8))
                        {
                            quote.PriceToFreeCashFlow = t8;
                        }
                        lst.Add(quote);
                    }
                }
            }
            return(lst.ToArray());
        }