Sleep 3 seconds and retrying 3 more time(s)

Hi All,

left my algo running to test it today, it is currently listening to 11 stocks, receiving minute updates. I came back to find this in the log:

sleep 3 seconds and retrying 3 more time(s)…
sleep 3 seconds and retrying 2 more time(s)…
sleep 3 seconds and retrying https// 1 more time(s)…
Closed Connection

I have never seen this error before, I would just like to understand what it is. Thanks to all who reply in advance.


this indicates a server communication issue.
when did you experience that? during market open hours or outside of market hours?
did it happen again?
what repository are you using? (backtrader, pylivetrader, direct alpaca-trade-api)
what happened when you restarted?

thanks for your reply, it started again fine. must be an alpaca issue

1 Like

I get it all day long. Even if I stop and wait 10 seconds. It’s annoying and it makes me lose money. There is no way I can run my script on auto because this error requires me to manually set up sells. The buys may post but once this error comes, I am screwed. Let me ask you, is this due to the web socket? Like the OP I have more than two stocks that I am following and trading at one time. Will using AL for ordering and Poly (paid plan) for data and the web socket connect spare me of this error code?

I’m 82% sure that is caused because you are exceeding the 200 per minute query limit alpaca has in place.

you have 2 choices for websocket connection as you mantioned (Alpaca data stream and Polygon data stream for paid accounts). of course - try both if you encounter an issue with the alpaca data steam.

no matter what you choose, your orders will be with Alpaca.

are you using python? if not what is your stack?
are you using the python SDK or doing it directly against the API servers?
are you using the backtrader integration or pylivetrader or did you write your own manager?

@GreenCauliflower and @TBD - I got this message too, and I can confirm it’s because I was making too many API calls per second. In Python, I now have a


after every API call, so the script basically pauses for half a second (which is conservative since we’re allowed to make about 3 calls per second) before making another call. Hope that helps.

I know I’m late but I’ll answer for others.

Polygon - I noticed it does not like me to run 3 or more scripts. If I do I get the error regardless of whether or not its buying or selling. I was able to confirm this today because I finally used IOC. My script gets every last tick in almost real time. No errors on two running.

Yes, Python.
Manager that uses AL API and Backtrader.

The problem is it does not like me to run more than 3 scripts at a time. Basically I can only follow two symbols or have two strategies. It sucks big time. I realized I need more than one account. Also, it doesn’t see to like “Day” and “Extending.” The minute I switched to ICO with Extended off (no choice), I was making big moves. LOL It worked how the paper account worked, super fast.