Well, it's probably less painful to set up your own id server.
Have one
app that requests id's from tws and have your trading software
request id's
from the id server instead of tws.
Yes, it's another layer of stuff but I suspect it's the only
reliable way
to get around the problem you are facing.
That was the first approach we took. It doesn't work, here's why.
Assume you have 10 orders outstanding, each with an id. Disconnect
from tws, and reconnect, the call the open orders request. You get
10 reports, and they have all been assigned NEW id's, starting at the
first id you got from the nextid callback.
I had to take your approach a whole layer farther. I now have 'the
trading application' running on the TWS machine, and it exports a
network accessible api. All of the other machines talk to that
application, not TWS itself. I took one look at the issues of having
multiple programs trying to keep order lists strait, when they have
different id's, and said 'no thanks'.