Iâm having a bit of an issue with order IDs using the C++ API. nextValidId() is called when you connect giving you the order ID to use for your first order. When I send an order I call reqIds() so as to make an new order ID available for my next order. This works fine if orders arenât sent in quick succession but problems can arise if you want to send a new order before nextValidId() has been called with the next order ID.
The obvious solution would be to request a number of IDs and put them in a queue so you would always have IDs on hand ready for the next order. Unfortunately though no matter what value you pass to reqIds() it only ever results in one call to nextValidId() and thus only one ID being sent.
As nextValidId() is called from the same thread you canât simply suspend execution until nextValidId() has been called and the new ID received. The only solution I can see would be to put the API code in its own thread and when suspend the main thread when a new ID is not available until nextValidId() has been called in the API thread with the next ID to use. However thatâs an absurd solution to deal with something as simple as generating a unique order ID and there must be an easier way. IBâs client2 project provides no answers sine it just gets the order ID from the value entered in the dialog box so Iâm unsure how this issue should be handled.
Do IB have a recommended way of handling this situation? If not, how did other people manage the issue?
Thanks for the help
The obvious solution would be to request a number of IDs and put them in a queue so you would always have IDs on hand ready for the next order. Unfortunately though no matter what value you pass to reqIds() it only ever results in one call to nextValidId() and thus only one ID being sent.
As nextValidId() is called from the same thread you canât simply suspend execution until nextValidId() has been called and the new ID received. The only solution I can see would be to put the API code in its own thread and when suspend the main thread when a new ID is not available until nextValidId() has been called in the API thread with the next ID to use. However thatâs an absurd solution to deal with something as simple as generating a unique order ID and there must be an easier way. IBâs client2 project provides no answers sine it just gets the order ID from the value entered in the dialog box so Iâm unsure how this issue should be handled.
Do IB have a recommended way of handling this situation? If not, how did other people manage the issue?
Thanks for the help