Environment
Language:
Python
Other Environment Details
Running on a dedicated AWS EC2 instance.
Problem
Summary
Seemingly just this week, I’ve been getting a significant number of timeout errors (like a dozen a day or so where I used to get none) that have been impacting my algos. Usually, I have enough smarts baked in that it can survive, but today it hit just at the perfect time and crashed the controller for one of my strategies. The exact error for this particular case is:
HTTPSConnectionPool(host=‘data.alpaca.markets’, port=443): Max retries exceeded with url: /v2/stocks/PAPL/bars?timeframe=1Min&start=2026-04-23T13:30:00Z&end=2026-04-23T13:31:00Z&limit=100&adjustment=raw&feed=sip&sort=asc (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x000001EA299FA710>, ‘Connection to data.alpaca.markets timed out. (connect timeout=None)’))
Paper or Live Tradng?
Live
Example Code:
Below is the function that it happened to catch today. However, it is definitely not the only call that’s hit it this past week.
def getOpeningCandle(ticker):
try: now_utc = datetime.datetime.now(timezone.utc) local_hour = datetime.datetime.now().hour utc_hour = now_utc.hour diff = (utc_hour - local_hour) % 24 if diff == 5: opening_utc_time = now_utc.replace(hour=13, minute=30, second=0, microsecond=0) elif diff == 6: opening_utc_time = now_utc.replace(hour=14, minute=30, second=0, microsecond=0) opening_utc_end = opening_utc_time + timedelta(minutes=1) opening_utc_time = opening_utc_time.strftime('%Y-%m-%dT%H:%M:%SZ') opening_utc_end = opening_utc_end.strftime('%Y-%m-%dT%H:%M:%SZ') url = (f"https://data.alpaca.markets/v2/stocks/{ticker}/bars?timeframe=1Min&start={opening_utc_time}&end={opening_utc_end}&limit=100&adjustment=raw&feed=sip&sort=asc") headers = { "accept": "application/json", "APCA-API-KEY-ID": API_Key, "APCA-API-SECRET-KEY": API_Secret } response = json.loads(requests.get(url, headers=headers).text) if response\['bars'\] is None: return None response = response\['bars'\]\[0\] item = { "open": str(response\['o'\]), "close": str(response\['c'\]), "high": str(response\['h'\]), "low": str(response\['l'\]), "volume": str(response\['v'\]), "vwap": str(response\['vw'\]), "price action": str(round(float(response\['c'\])\*float(response\['v'\]),2)), "UTC start time": str(opening_utc_time), "UTC end time": str(opening_utc_end), "trending": "null" } if float(item\['open'\]) > float(item\['close'\]): item\['trending'\] = "down" elif float(item\['open'\]) < float(item\['close'\]): item\['trending'\] = "up" elif float(item\['open'\]) == float(item\['close'\]): item\['trending'\] = "stagnant" return(item) except Exception as e: print("An error occurred during the function getOpeningCandle for " + ticker + ":\\n" + str(e) + "\\n") process_files.append("An error occurred during the function getOpeningCandle for " + ticker + ":\\n" + str(e) + "\\n", "main") if "ConnectionResetError" in str(e): return "ConnectionResetError" return None