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.

1 Like

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.

1 Like

I am also late here but chiming in in 2022:

I am using the python library alpaca_trade_api and was getting the following over and over forever during market hours on my paper account: 3 seconds and retrying 3 more time(s)…

I was using a modified version of the Scalping Algorithm in one of the Alpaca articles and code pulled directly from the AlpacaMarkets GitHub.

I figured out in order to get the scalping code to work I had change my Market Data Subscription plan from Free to Unlimited. Which seems counterintuitive to the concept of a paper account, let alone attempting code that Alpaca puts out itself for users to “try”.

Hope this helps someone avoid some head banging against the wall.



I am just starting with Alpaca, trying the recipies I find in GitHub using the paper account, unfortunatelly many of the recipies are broken (needs debugging).
For this one in aprticular, I get the following 10 seconds after starting and it goes forever

2022-07-13 20:55:37, 3 seconds and retrying 3 more time(s)…
2022-07-13 20:55:41, 3 seconds and retrying 3 more time(s)…
2022-07-13 20:55:45, 3 seconds and retrying 3 more time(s)…

@Shlomik thanks to your replies I manage to make a couple of recipies in the backtrader repo work, fingers crossed here

Is there a way to make the scalping example work without using the unlimited subcription proposed by @deanmayne?

many thanks in advance

Alpaca provides live data with websockets with their free tier. So for scalping purpose it should be fine.