Dear Forum,
My app received a read timeout error from the following call
quotes = self.api.get_quotes(symbol, start_time, end_time, limit=10)
The stack trace shows
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='data.alpaca.markets', port=443): Read timed out. (read timeout=None)
where the read timeout is None.
I’m curious why my app is still getting timed out?
What is Alpaca’s internally set timeout, if any, on the api.get_quotes() method?
How do I set a new timeout?
Or should I just catch this timeout exception in my app and implement retry?
Thanks!
The following is the entire stack trace:
23
CHPT
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 445, in _make_request
six.raise_from(e, None)
File "<string>", line 3, in raise_from
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 440, in _make_request
httplib_response = conn.getresponse()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 1347, in getresponse
response.begin()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 307, in begin
version, status, reason = self._read_status()
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/http/client.py", line 268, in _read_status
line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/socket.py", line 704, in readinto
return self._sock.recv_into(b)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1241, in recv_into
return self.read(nbytes, buffer)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/ssl.py", line 1099, in read
return self._sslobj.read(len, buffer)
TimeoutError: [Errno 60] Operation timed out
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 755, in urlopen
retries = retries.increment(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/util/retry.py", line 531, in increment
raise six.reraise(type(error), error, _stacktrace)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/packages/six.py", line 735, in reraise
raise value
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 699, in urlopen
httplib_response = self._make_request(
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 447, in _make_request
self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/urllib3/connectionpool.py", line 353, in _raise_timeout
raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='data.alpaca.markets', port=443): Read timed out. (read timeout=None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/paulz/Documents/trading/LevelDetector/local.py", line 52, in <module>
tops, bottoms = detector.get_levels_for_all_incremental_ranges(symbol, bars)
File "/Users/paulz/Documents/trading/LevelDetector/level_detector.py", line 38, in get_levels_for_all_incremental_ranges
slack = self._calc_slack_amount(symbol, range_end_ts=bars[end].t, bar_close_price=bars[end].c)
File "/Users/paulz/Documents/trading/LevelDetector/level_detector.py", line 74, in _calc_slack_amount
avg_spread = self._get_avg_spread(symbol, range_end_ts)
File "/Users/paulz/Documents/trading/LevelDetector/level_detector.py", line 85, in _get_avg_spread
quotes = self.api.get_quotes(symbol, start_time, end_time, limit=10)
File "/Users/paulz/Library/Python/3.9/lib/python/site-packages/alpaca_trade_api/rest.py", line 709, in get_quotes
quotes = list(self.get_quotes_iter(symbol,
File "/Users/paulz/Library/Python/3.9/lib/python/site-packages/alpaca_trade_api/rest.py", line 697, in get_quotes_iter
for quote in quotes:
File "/Users/paulz/Library/Python/3.9/lib/python/site-packages/alpaca_trade_api/rest.py", line 648, in _data_get
resp = self.data_get(path, data=data, api_version=api_version)
File "/Users/paulz/Library/Python/3.9/lib/python/site-packages/alpaca_trade_api/rest.py", line 255, in data_get
return self._request(
File "/Users/paulz/Library/Python/3.9/lib/python/site-packages/alpaca_trade_api/rest.py", line 202, in _request
return self._one_request(method, url, opts, retry)
File "/Users/paulz/Library/Python/3.9/lib/python/site-packages/alpaca_trade_api/rest.py", line 221, in _one_request
resp = self._session.request(method, url, **opts)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/requests/adapters.py", line 529, in send
raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='data.alpaca.markets', port=443): Read timed out. (read timeout=None)