Broker API HubMenu

Python exception

Python exception: asyncio.CancelledError

As text you can copy

asyncio.CancelledError
Kind
Exception
Where you meet it
Raised in your own program
Read from
Python 3 documentation, asyncio, Exceptions

What does asyncio.CancelledError mean in Python?

The operation has been cancelled. It can be caught to do custom work when a task is cancelled, and the documentation says that in almost all situations it must be raised again. Since Python 3.8 it is a subclass of BaseException.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialdocs.python.orgchecked

What it means in trading API work

A task in your program was cancelled: by your own code, by a timeout wrapper or at shutdown. It is not an error from the broker. A task cancelled part way through an order request leaves the outcome unknown.

This part is this site's own explanation, written for people learning to call a trading API. It is not part of the source cited above and it describes no particular broker.

What should I do about asyncio.CancelledError?

Do not swallow it: clean up and raise it again. If a task that talks to the API was cancelled in the middle of a request, check the state of the account before the program sends anything else.

This page is an independent explanation in plain words. The definition itself is in the source it was read from, which is the authority if the two ever differ.