public void ParseMultiQuotesTest()
        {
            Country           country     = Country.Taiwan;
            string            stockId     = "2002";
            string            htmlContent = TestUtilities.ReadTestFile(YahooMultiQuotesFilename);
            IStockQuoteParser parser      = new YahooFinanceParser();

            IReadOnlyList <IStockQuoteFromDataSource> quotes = parser.ParseMultiQuotes(country, stockId, htmlContent, WriteToErrorLogAction);

            Assert.NotNull(quotes);
            foreach (IStockQuoteFromDataSource quote in quotes)
            {
                Assert.True(quote.IsValid);
            }
        }
Exemple #2
0
        private bool QueryYahooFinanceProfile(ref StockProfile aStock)
        {
            String nYahooQueryStr = YahooFinanceParser.PROFILE_STR;

            nYahooQueryStr = nYahooQueryStr.Replace("@TICK", getYahooSymbol(aStock, aStock.Sym));

            String             nYahooHtmlStr = RESTController.GetREST(nYahooQueryStr);
            YahooFinanceParser nYahooParser  = new YahooFinanceParser(aStock);

            if (nYahooParser.StartHTML(nYahooHtmlStr))
            {
                return(true);
            }

            return(false);
        }
        private IStockQuoteDataSource CreateStockSource(Contracts.StockQuoteSource sourceKind)
        {
            switch (sourceKind)
            {
            case Contracts.StockQuoteSource.Yahoo:
                IStockQuoteParser yahooParser = new YahooFinanceParser();
                return(new YahooFinanceDataSource(_configuration, _dataSourceOperations, yahooParser));

            case Contracts.StockQuoteSource.AlphaVantage:
                IStockQuoteParser alphaVantageParser = new AlphaVantageParser();
                return(new AlphaVantageDataSource(_configuration, _dataSourceOperations, alphaVantageParser));

            case Contracts.StockQuoteSource.Test:
                // There is no test data source required
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(sourceKind), sourceKind, null);
            }

            return(null);
        }
        public void ParseSingleQuoteTest()
        {
            Country           country     = Country.USA;
            string            stockId     = "DRV";
            string            htmlContent = TestUtilities.ReadTestFile(YahooHtmlTestFilename);
            IStockQuoteParser parser      = new YahooFinanceParser();

            IStockQuoteFromDataSource quote = parser.ParseSingleQuote(country, stockId, htmlContent, WriteToErrorLogAction);

            Assert.NotNull(quote);
            Assert.True(quote.IsValid);
            Assert.Equal(14.63m, quote.ClosePrice);
            Assert.Equal(15.0686m, quote.HighPrice);
            Assert.Equal(14.611m, quote.LowPrice);
            Assert.Equal(14.79m, quote.OpenPrice);
            Assert.Equal(67165, quote.Volume);
            Assert.Equal(stockId, quote.StockId);
            Assert.Equal(country, quote.Country);
            Assert.Equal(2018, quote.TradeDateTime.Year);
            Assert.Equal(3, quote.TradeDateTime.Month);
            Assert.Equal(2, quote.TradeDateTime.Day);
            Assert.Equal(15, quote.TradeDateTime.Hour);
            Assert.Equal(59, quote.TradeDateTime.Minute);
        }