Yahoo public api返回结果为null。什么是实时获取库存数据的另一种选择

时间:2017-12-15 13:51:07

标签: yahoo-finance yahoo-api

我在api下面使用过:

https://query.yahooapis.com/v1/public/yql?q=select%20 *%20from%20yahoo.finance.quotes%20where%20symbol%20英寸%20(%22AVGO%22)及格式= JSON&安培;诊断=真安培; ENV =商店%3A%2F%2Fdatatables .ORG%2Falltableswithkeys&安培;回调=

它在json下面返回:

{     "查询":{         "计数":0,         "创建":" 2017-12-15T10:17:09Z",         " lang":" en-US",         " diagnostics":{             "重定向":[{                 "来自":" / ec?url = http%3a%2f%2fwww.datatables.org%2fyahoo%2ffinance%2fyahoo.finance.quotes.xml& t = 1513333026& ttl = 60& SIG = 5p8s71uMOfbvHH8Cx7iHVQ--〜d&#34 ;,                 " status":" 307",                 "内容":" http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml"             },{                 "从&#34 ;:"?/ EC URL = HTTP%3A%2F%2fdownload.finance.yahoo.com%2FD%2fquotes.csv%3FF%3daa2bb2b3b4cc1c3c4c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy%26S%3dAVGO& T公司= 1513333029&安培; TTL = 60安培; SIG = lMli2lKRDkqtxVXcjK.Vyg--〜d&#34 ;,                 " status":" 307",                 "内容":" http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c4c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=AVGO"             }],             " url":[{                 "执行 - 开始时间":" 0",                 "执行停止时间":" 2",                 "执行时间":" 2",                 "内容":" http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml"             },{                 "执行 - 开始时间":" 2504",                 "执行停止时间":" 2509",                 "执行时间":" 5",                 " http-status-code":" 403",                 " http-status-message":"禁止",                 "内容":" http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c4c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=AVGO"             }],             " opensCallable":" true",             "缓存":{                 "错误":"等待操作超时 - 节点失败:memcache3.yql.gq1.yahoo.com/206.190.36.58:11211",                 "执行 - 开始时间":" 3",                 "执行停止时间":" 2503",                 "执行时间":" 2500",                 "方法":" GET",                 "输入":" MEMCACHED",                 "内容":" 5d1e1de680846a307c9874dc3d6878dc"             },             " javascript":["无法从缓存中检索查询结果,超时等待操作 - 失败的节点:memcache3.yql.gq1.yahoo.com/206.190.36.58:11211", {                 "执行 - 开始时间":" 2",                 "执行停止时间":" 2509",                 "执行时间":" 2506",                 "使用说明":" 12000",                 " table-name":" yahoo.finance.quotes"             }],             " csv":"列不匹配:[Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,Change& PercentChange,Change,Commission,Currency,ChangeRealtime,AfterHoursChangeRealtime,DividendShare,LastTradeDate,TradeDate,EarningsShare ,ErrorIndicationreturnedforsymbolchangedinvalid,EPSEstimateCurrentYear,EPSEstimateNextYear,EPSEstimateNextQuarter,DaysLow,DaysHigh,YearLow,YearHigh,HoldingsGainPercent,AnnualizedGain,HoldingsGain,HoldingsGainPercentRealtime,HoldingsGainRealtime,MoreInfo,OrderBookRealtime,MarketCapitalization,MarketCapRealtime,EBITDA,ChangeFromYearLow,PercentChangeFromYearLow,LastTradeRealtimeWithTime,ChangePercentRealtime,ChangeFromYearHigh,PercebtChangeFromYearHigh,LastTradeWithTime ,LastTradePriceOnly,HighLimit,LowLimit,DaysRange,DaysRangeRealtime,FiftydayMovingAverage,TwoHundreddayMovingAverage,ChangeFromTwoHundreddayMovingAverage,PercentChangeFromTwoHundreddayMovingAverage,ChangeFromFiftydayMovingAverage,Percent ChangeFromFiftydayMovingAverage,Name,Notes,Open,PreviousClose,PricePaid,ChangeinPercent,PriceSales,PriceBook,ExDividendDate,PERatio,DividendPayDate,PERatioRealtime,PEGRatio,PriceEPSEstimateCurrentYear,PriceEPSEstimateNextYear,Symbol,SharesOwned,ShortRatio,LastTradeTime,TickerTrend,OneyrTargetPrice,Volume,HoldingsValue,HoldingsValueRealtime, YearRange,DaysValueChange,DaysValueChangeRealtime,StockExchange,DividendYield] vs Yahoo! - 403 Forbidden - 错误403我们注意到此服务的使用违反了Yahoo服务条款。因此,该服务正在停止。有关所有未来市场和股票数据研究,请参阅finance.yahoo.com。",             "查询":{                 "执行 - 开始时间":" 2503",                 "执行停止时间":" 2509",                 "执行时间":" 6",                 " params":" {url = [http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c4c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=AVGO]}",                 "内容":"从csv中选择*其中url = @ url和columns =' Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,Change& PercentChange,Change,Commission,Currency ,ChangeRealtime,AfterHoursChangeRealtime,DividendShare,LastTradeDate,TradeDate,EarningsShare,ErrorIndicationreturnedforsymbolchangedinvalid,EPSEstimateCurrentYear,EPSEstimateNextYear,EPSEstimateNextQuarter,DaysLow,DaysHigh,YearLow,YearHigh,HoldingsGainPercent,AnnualizedGain,HoldingsGain,HoldingsGainPercentRealtime,HoldingsGainRealtime,MoreInfo,OrderBookRealtime,MarketCapitalization,MarketCapRealtime,EBITDA,ChangeFromYearLow ,PercentChangeFromYearLow,LastTradeRealtimeWithTime,ChangePercentRealtime,ChangeFromYearHigh,PercebtChangeFromYearHigh,LastTradeWithTime,LastTradePriceOnly,HighLimit时,LowLimit时,DaysRange,DaysRangeRealtime,FiftydayMovingAverage,TwoHundreddayMovingAverage,ChangeFromTwoHundreddayMovingAverage,PercentChangeFromTwoHundreddayMovingAverage,ChangeFromFiftydayMovingAverage,PercentChangeFromFifty dayMovingAverage,名称,备注,打开,PreviousClose,PricePaid,ChangeinPercent,PriceSales,价目表,除息日,操作,DividendPayDate,PERatioRealtime,PEGRatio,PriceEPSEstimateCurrentYear,PriceEPSEstimateNextYear,符号,SharesOwned,ShortRatio,LastTradeTime,TickerTrend,OneyrTargetPrice,音量,HoldingsValue,HoldingsValueRealtime, YearRange,DaysValueChange,DaysValueChangeRealtime,股票交易所,现金殖利率'"             },             "用户时间":" 2509",             "服务时间":" 2507",             " build-version":" 2.0.217"         },         "结果":null     } }

2 个答案:

答案 0 :(得分:1)

雅虎关闭他们的股票api。

答案 1 :(得分:1)

您可以使用yahoo_fin包获取实时数据。它的文档在这里:http://theautomatic.net/yahoo_fin-documentation/。你主要需要两个函数 - get_data和get_quote_table。

如果您想要实时价格,可以这样做:

from yahoo_fin.stock_info import get_data, get_quote_table

# get current price for Apple's stock
get_data("AAPL").close[-1]

在交易日运行上述代码将获得当前的实时价格。

如果您需要其他信息,例如引用页面上提供的信息(例如https://finance.yahoo.com/quote/AAPL?p=AAPL),您可以使用get_quote_table函数:

get_quote_table("AAPL")

所以你只需要更换" AAPL"用你想要的任何股票代码符号。

yahoo_fin软件包还具有从S& P,NASDAQ和Dow获取股票代码列表的功能 - 因此,如果您想为这些股票提取所有数据,您可以循环这些函数返回的股票代码列表。

from yahoo_fin.stock_info import tickers_dow

# get all Dow tickers
dow_tickers = tickers_dow()

# get price data for Dow stocks
dow_data = {ticker : get_data(ticker) for ticker in dow_tickers}