antequant / blotter

Microservice to connect to Interactive Brokers and stream market data into Google BigQuery
MIT License
1 stars 4 forks source link

Detect any blocking on IB thread #27

Closed jspahrsummers closed 4 years ago

jspahrsummers commented 4 years ago

From the docs:

While some of the request methods are blocking from the perspective of the user, the framework will still keep spinning in the background and handle all messages received from TWS/IBG. It is important to not block the framework from doing its work. If, for example, the user code spends much time in a calculation, or uses time.sleep() with a long delay, the framework will stop spinning, messages accumulate and things may go awry.

The one rule when working with the IB class is therefore that user code may not block for too long.

...

So what is “too long”? That depends on the situation. If, for example, the timestamp of tick data is to remain accurate within a millisecond, then the user code must not spend longer than a millisecond. If, on the other extreme, there is very little incoming data and there is no desire for accurate timestamps, then the user code can block for hours.

We could detect this by timestamping before and after operations that get thrown to the IBThread.

jspahrsummers commented 4 years ago

Seems this can be more easily achieved with the built-in asyncio debug mode.