开云体育

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

Re: Question on nextValidId function


 

There is nothing wrong with your approach, as long as your internal counter gets initialized with the value of the automatic nextValidId() callback you receive when your client connects to TWS API.

If your client gets "in contact" with orders from other clients, you need to adjust your interal counter so that it is higher than the orderId of all orders your client sees. That is mostly important for client 0 and the master client since they receive openOrder() callback for orders placed by other clients or TWS in real time, but all clients might need to do that in case they request all open orders, for example, and the list contains order from other clients.

The simplest approach is that your openOrder() callback makes sure that your internal counter is always higher than all orderIds it sees.

闯ü谤驳别苍

?
On Fri, Dec 27, 2024 at 08:03 AM, Marco wrote:

Hi All,

one question on the orderId and the necessity of nextValidId function. From the documentation () it is stated that “if there are multiple client applications connected to one account, it is necessary to use an order ID with new orders which is greater than all previous order IDs returned to the client application in openOrder or orderStatus callbacks?”. so I expect that the nextValidId function is needed in case of multiple clients for one account. However i have created a program in python that handles orderIds internally without relying on the nextvalidid function. By launching multiple instances of it (each with different client id) I see no problems in handling orders (each client autonomously updating its orderId). What am I missing? Is nextValidId really needed?

thanks,

Marco

?

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