Has Yahoo finance web service disappeared? API changed? Down temporarily?

后端 未结 9 1502
礼貌的吻别
礼貌的吻别 2020-11-27 13:12

For quite some time I\'ve been using the following REST API to query Yahoo finance for current prices. It is documented in several Stack Overflow posts, e.g. Yahoo finance

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 13:42

    Check out this excellent API Wrapper, available on NuGet: https://github.com/salmonthinlion/YahooFinanceApi

    Get stock quotes

    var quotes = await Yahoo.Symbol("AAPL", "GOOG").Tag(Tag.LastTradePriceOnly, Tag,ChangeAndPercentChange, Tag.DaysLow, Tag.DaysHigh).GetAsync();
    var aapl = quotes["AAPL"];
    var price = aapl[Tag.LastTradePriceOnly];
    

    Get historical data for a stock

    // You should be able to query data from various markets including US, HK, TW
    var history = await Yahoo.GetHistoricalAsync("AAPL", new DateTime(2016, 1, 1), new DateTime(2016, 7, 1), Period.Daily);
    foreach (var candle in history)
    {
        Console.WriteLine($"DateTime: {candle.DateTime}, Open: {candle.Open}, High: {candle.High}, Low: {candle.Low}, Close: {candle.Close}, Volume: {candle.Volume}, AdjustedClose: {candle.AdjustedClose}");
    }
    

    Get dividend history for a stock

    // You should be able to query data from various markets including US, HK, TW
    var dividendHistory = await Yahoo.GetHistoricalDividendsAsync("AAPL", new DateTime(2016, 1, 1), new DateTime(2016, 7, 1));
    foreach (var candle in dividendHistory)
    {
        Console.WriteLine($"DateTime: {candle.DateTime}, Dividend: {candle.Dividend}");
    }
    

提交回复
热议问题