I used below api:
https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AVGO%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=
It is returning below json:
{
“query”: {
“count”: 0,
“created”: “2017-12-15T10:17:09Z”,
“lang”: “en-US”,
“diagnostics”: {
“redirect”: [{
“from”: “/ec?url=http%3a%2f%2fwww.datatables.org%2fyahoo%2ffinance%2fyahoo.finance.quotes.xml&t=1513333026&ttl=60&sig=5p8s71uMOfbvHH8Cx7iHVQ–~D”,
“status”: “307”,
“content”: “http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml”
}, {
“from”: “/ec?url=http%3a%2f%2fdownload.finance.yahoo.com%2fd%2fquotes.csv%3ff%3daa2bb2b3b4cc1c3c4c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy%26s%3dAVGO&t=1513333029&ttl=60&sig=lMli2lKRDkqtxVXcjK.Vyg–~D”,
“status”: “307”,
“content”: “http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c4c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=AVGO”
}],
“url”: [{
“execution-start-time”: “0”,
“execution-stop-time”: “2”,
“execution-time”: “2”,
“content”: “http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml”
}, {
“execution-start-time”: “2504”,
“execution-stop-time”: “2509”,
“execution-time”: “5”,
“http-status-code”: “403”,
“http-status-message”: “Forbidden”,
“content”: “http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c4c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=AVGO”
}],
“publiclyCallable”: “true”,
“cache”: {
“error”: “Timed out waiting for operation – failing node: memcache3.yql.gq1.yahoo.com/206.190.36.58:11211”,
“execution-start-time”: “3”,
“execution-stop-time”: “2503”,
“execution-time”: “2500”,
“method”: “GET”,
“type”: “MEMCACHED”,
“content”: “5d1e1de680846a307c9874dc3d6878dc”
},
“javascript”: [“Unable to retrieve query results from cache, Timed out waiting for operation – failing node: memcache3.yql.gq1.yahoo.com/206.190.36.58:11211”, {
“execution-start-time”: “2”,
“execution-stop-time”: “2509”,
“execution-time”: “2506”,
“instructions-used”: “12000”,
“table-name”: “yahoo.finance.quotes”
}],
“csv”: “Column mismatch: [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, PercentChangeFromFiftydayMovingAverage, 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 — error 403It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com.”,
“query”: {
“execution-start-time”: “2503”,
“execution-stop-time”: “2509”,
“execution-time”: “6”,
“params”: “{url=[http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c4c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=AVGO]}”,
“content”: “select * from csv where url=@url and 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,PercentChangeFromFiftydayMovingAverage,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'”
},
“user-time”: “2509”,
“service-time”: “2507”,
“build-version”: “2.0.217”
},
“results”: null
}
}
2
Answers
Yahoo shut their stock api down.
You can get live data using the yahoo_fin package. Its documentation is here: http://theautomatic.net/yahoo_fin-documentation/. You’ll mainly need two functions from it — get_data, and get_quote_table.
If you want live prices, you can do this:
Running the above code during the trading day will get you the current live price.
If you want other information, like what’s available on the quote page (e.g. https://finance.yahoo.com/quote/AAPL?p=AAPL), you can use the get_quote_table function:
So you just need to replace “AAPL” with whatever ticker symbols you want.
The yahoo_fin package also has functions to get ticker lists from the S&P, NASDAQ, and Dow — so if you want to pull all the data for those, you can just loop the ticker lists those functions return.