Event loop stopped before Future completed

My trading algo is running just fine, EXCEPT, every hour or two I get this error which stops the program.
“Event loop stopped before Future completed.”
Communications protocols age Greek to me.
Can anyone please give me a clue as to how I can stop this error.

This has to do with python’s async loop. It means queued task was not finished. Probably inside SDK, but we’d have to check.

Thank you. I suspected it may be something like that. I do not know how I can get around this problem. It happened five times today.
can you give me any suggestions? I am pretty desperate.

if name == ‘main’:
trader = MartTrader()

trader.start_trading(11) <----- the exception points to this line
I tried to put it inside a “try clause” but I could not ger it to work
Thanks for your consideration.

Good Morning Adam,
Another point on this error: It started on the same day that you introduced the “Alpaca data API”
Perhaps the problem is related to that.
I am now running with the Polygon feed. I thought about trying the “Alpaca data API” but the instructions are so confusing that a am afraid to try it. What you need is an example that shows how to set up each of them, Alpaca and Polygon. The example should contain no superficial code.

Please give this request for an example your upmost priority and make it in Python.
I know you are working hard and have a lot of problems to solve, but it seems to me that this one should be at the top of the list,

This probably has to do with the new python SDK version. If you need urgent solution, you may try downgrade to 0.46

How ,like this?

api = tradeapi.REST(key_id, secret_key, base_url, api_version=‘0.46’)
Thanks for a quick response.

You can uninstall alpaca-trade-api and install like pip install alpaca-trade-api=="0.46"

Dear Adam,
Thank you, This is my set up now.

!pip install alpaca-trade-api==“0.46”

I ran this for the last hour today. I will let you know tomorrow if it resolved the problem.

Hi Adam,
I ran all day without the “Event loop stopped before Future completed” error . So I guess that fixed it.
Thanks a lot.
One more thing.
Please send a sample of python code to submit a oco order.
Can I use JSON in python to submitt orders?
Where can I find sample code.
Have a good weekend.
Best regards,

1 Like