Not sure what needs to be tested here since the documentation at is crystal clear.? Also not clear why you are still trying to force the API into some kind of a "server increments orderIds"? mode. That is not how it works and you just need to accept that. For your convenience, below and annotated copy of the first paragraph of Perhaps the most important event received after successfully connecting to the TWS is the [...] As its name indicates, the nextValidId event provides the next valid identifier needed to place an order. This identifier is nothing more than the next number in the sequence. This means that if there is a single client application submitting orders to an account, it does not have to obtain a new valid identifier every time it needs to submit a new order. It is enough to increase the last value received from the nextValidId method by one. For example, if the valid identifier for your first API order is 1, the next valid identifier would be 2 and so on. This is what you should do for now. The situation may become a little more complicated as JG has suggested when orders can simultaneously be placed by multiple clients and TWS. Particularly if one of those clients is the "Master Client" (received order status for all orders placed by all clients) or "Client 0" (receives orders order status updates for all orders placed in TWS). The documentation is again crystal clear for that case: However 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. In your TWS API adapter (the small layer of code that shields your business logic from any and all TWS API details), you'd provide a very simple nextOrderId() service that works as follows:
You obviously want to put some synchronization in place to make sure increment and set operations are atomic. The final piece of documentation says: You can always use the method in the event that your client application loses track of the sequence. I hope this settles it.´³¨¹°ù²µ±ð²Ô On Mon, Aug 7, 2023 at 08:18 AM, Arthur wrote:
@ ´³¨¹°ù²µ±ð²Ô |