public async Task <List <StockHistoricalPrice> > GoogleGetHistoricalPrice(
            string symbolType,
            string symbol,
            DateTime start,
            DateTime end)
        {
            //first get a valid token from Yahoo Finance
            var importerHistorical         = new GoogleFinanceImporter();
            IReadOnlyList <IOhlcv> candles = await importerHistorical.ImportAsync(symbolType + symbol, start, end);

            //Historyprice轉換為HistoryPriceExtStkCode類型, 新增StkCode後傳回
            List <StockHistoricalPrice> shpList = new List <StockHistoricalPrice>();

            foreach (Candle candle in candles)
            {
                shpList.Add(
                    new StockHistoricalPrice(
                        symbol,
                        candle.DateTime,
                        candle.Open,
                        candle.High,
                        candle.Low,
                        candle.Close,
                        candle.Volume));
            }

            return(shpList);
        }
示例#2
0
        public void ImportByGoogleFinance()
        {
            var importer = new GoogleFinanceImporter();
            var candle   = importer.ImportAsync("NASDAQ/AAPL", new DateTime(2017, 1, 3), new DateTime(2017, 1, 3)).Result.First();

            Assert.AreEqual(candle.Open, 115.8m);
            Assert.AreEqual(candle.High, 116.33m);
            Assert.AreEqual(candle.Low, 114.76m);
            Assert.AreEqual(candle.Close, 116.15m);
            Assert.AreEqual(candle.Volume, 28_781_865);
        }