¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Re: Connection disconnects immediately after connect with PACEAPI enabled


 

¿ªÔÆÌåÓý

Waiting for the nextValidID callback before calling other API seems to have fixed the issue.? Thanks for your help.


From: [email protected] <[email protected]> on behalf of ´³¨¹°ù²µ±ð²Ô Reinold via groups.io <TwsApiOnGroupsIo@...>
Sent: Tuesday, March 22, 2022 8:17 PM
To: [email protected] <[email protected]>
Subject: Re: [TWS API] Connection disconnects immediately after connect with PACEAPI enabled
?
Crow,

the issue with your code is not the .setConnectOptions("+PACEAPI") call. It is rather the location (timing) of the reqPosition() and reqMarketDataType() calls.

You might want to reread the section in the API Reference Guide. You should not send any request toe TWS API until you have received the BApi.EWrapper.nextValidID callback. That is your indication that all API components have been initialized properly and messages can flow in both directions. Your code calls reqPosition() and reqMarketDataType() before that callback has arrived.

There are other areas that can be improved. The ApiContoller.java file in the IBKR API distribution is a very good example of how you might want to structure your interface with the TWS API.

´³¨¹°ù²µ±ð²Ô

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