Ejemplo n.º 1
0
        private List<Security> ParseSecurities(XDocument doc)
        {
            if (doc == null)
                return null;

            List<Security> securities = new List<Security>();
            IEnumerable<XElement> quotes = doc.Root.Descendants("finance");

            foreach (var quote in quotes)
            {
                var symbol = GetAttributeData(quote, "symbol");
                var exchange = GetAttributeData(quote, "exchange");
                var last = GetDecimal(quote, "last");
                var change = GetDecimal(quote, "change");
                var percentChange = GetDecimal(quote, "perc_change");
                var company = GetAttributeData(quote, "company");

                //if (exchange.ToUpper() == "MUTF") //handle mutual fund
                if (exchange.ToUpper() == "NASDAQ") //handle mutual fund
                {
                    var mf = new MutualFund();
                    mf.Symbol = symbol;
                    mf.Last = last;
                    mf.Change = change;
                    mf.PercentChange = percentChange;
                    mf.RetrievalDateTime = DateTime.Now;
                    mf.Company = company;
                    securities.Add(mf);
                }
            }
            return securities;
        }
Ejemplo n.º 2
0
        private List<Security> ParseSecurities(XDocument doc)
        {
            if (doc == null) return null;
            List<Security> securities = new List<Security>();

            IEnumerable<XElement> quotes = doc.Root.Descendants("finance");

            foreach (var quote in quotes)
            {
                var symbol = GetAttributeData(quote, "symbol");
                var exchange = GetAttributeData(quote, "exchange");
                var last = GetDecimal(quote, "last");
                var change = GetDecimal(quote, "change");
                var percentChange = GetDecimal(quote, "perc_change");
                var company = GetAttributeData(quote, "company");

                if (exchange.ToUpper() == "MUTF") //Handle mutual fund
                {
                    var mf = new MutualFund();
                    mf.Symbol = symbol;
                    mf.Last = last;
                    mf.Change = change;
                    mf.PercentChange = percentChange;
                    mf.RetrievalDateTime = DateTime.Now;
                    mf.Company = company;
                    securities.Add(mf);
                }
                else //Handle stock
                {
                    var stock = new Stock();
                    stock.Symbol = symbol;
                    stock.Last = last;
                    stock.Change = change;
                    stock.PercentChange = percentChange;
                    stock.RetrievalDateTime = DateTime.Now;
                    stock.Company = company;
                    stock.Exchange = new Exchange { Title = exchange };
                    stock.DayHigh = GetDecimal(quote, "high");
                    stock.DayLow = GetDecimal(quote, "low");
                    stock.Volume = GetDecimal(quote, "volume");
                    stock.AverageVolume = GetDecimal(quote, "avg_volume");
                    stock.MarketCap = GetDecimal(quote, "market_cap");
                    stock.Open = GetDecimal(quote, "open");
                    securities.Add(stock);
                }
            }
            return securities;
        }