开云体育

ctrl + shift + ? for shortcuts
© 2025 开云体育

Re: next valid id on initial connection


 
Edited

The TWS API is asynchronous by design and there is no guarantee as to the time it takes for a response to arrive after the corresponding request has been made. Under no circumstance should you ever use sleep to synchronize requests and responses. And while you are correct that many sample programs (even some from IBKR) frequently use sleep, it is completely wrong and dangerous to do so.

If you do need to block your main thread until a callback for a request comes in (in your case nextOrderId), use one of the "wait/notify" mechanisms your programming language provides.

For an example how you can do this in Python take a look at the i where Ewald de Wit provides both asynchronous as well as and synchronous (blocking) versions for each request. In your case, client.connect() blocks the caller (wait not sleep) until all callbacks related to the client connection request have taken place.

We use Java and our request methods return that give the caller the option to treat the request as asynchronous (caller keeps on working on other tasks while the request is being processed) or synchronous (blocks the caller until the response arrives) or a combination of both.

闯ü谤驳别苍

Join [email protected] to automatically receive all group messages.