为什么 pandas_datareader 停止从 IEX 和 Robinhood API 检索数据
Why has pandas_datareader stopped retrieving data from IEX and Robinhood APIs
一段时间以来,我一直在使用 pandas_datareader 从 IEX 和 Robinhood API 中检索股票价格,没有任何障碍。然而,最近(本周初),我的代码开始失败。
这是代码和错误:
IEX API
import pandas_datareader.data as web
import datetime as dt
end = dt.datetime.today()
start = end - relativedelta(months=20)
data = web.DataReader('MSFT', 'iex', start, end)
错误:
web.DataReader('MSFT', 'iex', start, end)
Traceback (most recent call last):
File "<ipython-input-88-2781d4515d5c>", line 1, in <module>
web.DataReader('MSFT', 'iex', start, end)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/data.py", line 322, in DataReader
session=session).read()
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/iex/daily.py", line 91, in read
self._get_params(self.symbols))
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 84, in _read_one_data
out = self._read_url_as_StringIO(url, params=params)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 95, in _read_url_as_StringIO
response = self._get_response(url, params=params)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 155, in _get_response
raise RemoteDataError(msg)
RemoteDataError: Unable to read URL: https://api.iextrading.com/1.0/stock/market/batch?symbols=MSFT&types=chart&range=2y
Response Text:
b'Forbidden'
罗宾汉API
import pandas_datareader.data as web
import datetime as dt
end = dt.datetime.today()
start = end - relativedelta(months=20)
data = web.DataReader('MSFT', 'robinhood', start, end)
错误:
web.DataReader('MSFT', 'robinhood', start, end)
Traceback (most recent call last):
File "<ipython-input-90-0a0fc1b0d4ce>", line 1, in <module>
web.DataReader('MSFT', 'robinhood', start, end)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/data.py", line 391, in DataReader
session=session).read()
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 77, in read
return self._read_one_data(self.url, self.params)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 86, in _read_one_data
out = self._get_response(url, params=params).json()
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 136, in _get_response
last_response_text = response.text.encode(response.encoding)
TypeError: encode() argument 1 must be str, not None
确切的代码直到最近才正常工作。我想知道发生了什么变化,我可以做些什么来纠正它。
来自https://iextrading.com/developer/docs/#stocks
"On June 1, 2019, IEX Group removed all non-IEX data, and certain functionality, according to the schedule. IEX Cloud, a non-Exchange platform, will continue to provide access to third-party data sources."
看来您需要访问密钥和密钥才能调用他们的 API。我正在为遇到此问题的 python 应用程序 stock_quote 调查此问题。
pandas_datareader 文档中列出的大多数 API 已被弃用,并且通过 pandas_datareader 框架(Yahoo、Google 等)不再有效。
然而,Tiingo 工作得很好,至少现在是这样。
要使用 Tiingo API,您首先需要注册一个免费帐户(如果您需要高级功能,则需要付费)。你可以做到 here. After activating your Tiingo account, you'll receive an API key which you can use to retrieve stock historical data with pandas_datareader (find details here).
您可以使用 Yahoo Finance 的高效 Python 库,yfinance
(GitHub link)。
一段时间以来,我一直在使用 pandas_datareader 从 IEX 和 Robinhood API 中检索股票价格,没有任何障碍。然而,最近(本周初),我的代码开始失败。
这是代码和错误:
IEX API
import pandas_datareader.data as web
import datetime as dt
end = dt.datetime.today()
start = end - relativedelta(months=20)
data = web.DataReader('MSFT', 'iex', start, end)
错误:
web.DataReader('MSFT', 'iex', start, end)
Traceback (most recent call last):
File "<ipython-input-88-2781d4515d5c>", line 1, in <module>
web.DataReader('MSFT', 'iex', start, end)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/data.py", line 322, in DataReader
session=session).read()
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/iex/daily.py", line 91, in read
self._get_params(self.symbols))
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 84, in _read_one_data
out = self._read_url_as_StringIO(url, params=params)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 95, in _read_url_as_StringIO
response = self._get_response(url, params=params)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 155, in _get_response
raise RemoteDataError(msg)
RemoteDataError: Unable to read URL: https://api.iextrading.com/1.0/stock/market/batch?symbols=MSFT&types=chart&range=2y
Response Text:
b'Forbidden'
罗宾汉API
import pandas_datareader.data as web
import datetime as dt
end = dt.datetime.today()
start = end - relativedelta(months=20)
data = web.DataReader('MSFT', 'robinhood', start, end)
错误:
web.DataReader('MSFT', 'robinhood', start, end)
Traceback (most recent call last):
File "<ipython-input-90-0a0fc1b0d4ce>", line 1, in <module>
web.DataReader('MSFT', 'robinhood', start, end)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/data.py", line 391, in DataReader
session=session).read()
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 77, in read
return self._read_one_data(self.url, self.params)
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 86, in _read_one_data
out = self._get_response(url, params=params).json()
File "/anaconda3/lib/python3.7/site-packages/pandas_datareader/base.py", line 136, in _get_response
last_response_text = response.text.encode(response.encoding)
TypeError: encode() argument 1 must be str, not None
确切的代码直到最近才正常工作。我想知道发生了什么变化,我可以做些什么来纠正它。
来自https://iextrading.com/developer/docs/#stocks
"On June 1, 2019, IEX Group removed all non-IEX data, and certain functionality, according to the schedule. IEX Cloud, a non-Exchange platform, will continue to provide access to third-party data sources."
看来您需要访问密钥和密钥才能调用他们的 API。我正在为遇到此问题的 python 应用程序 stock_quote 调查此问题。
pandas_datareader 文档中列出的大多数 API 已被弃用,并且通过 pandas_datareader 框架(Yahoo、Google 等)不再有效。
然而,Tiingo 工作得很好,至少现在是这样。
要使用 Tiingo API,您首先需要注册一个免费帐户(如果您需要高级功能,则需要付费)。你可以做到 here. After activating your Tiingo account, you'll receive an API key which you can use to retrieve stock historical data with pandas_datareader (find details here).
您可以使用 Yahoo Finance 的高效 Python 库,yfinance
(GitHub link)。