开云体育

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

Re: Connect to TWS in main not in Thread (Java)


btw12342001
 

--- In TWSAPI@..., twsapi <no_reply@...> wrote:



Hi btw12342001,
Call me brian :). I have no idea how to change that login name.

thanks so much for the tip! That actually helps me a lot. I still did not completely understood your earlier reply on how to handle returned data. In which method is the returned data handled?
If you scroll down in Example1.java you will see the tickPrice method. This is overriding the method of the same name in ExampleBase. All data from the TWS socket gets sent to those methods in ExampleBase unless they are overridden.

If you want more than one symbol you have to assign an separate id in the request and then do something in tickPrice based on the returned tickerId.

I guess if the connection is not limited to just one thread you also run into synchronization issues between the threads. But as far as I understood you can initiate 6 or 8 connections but IB recommends to use as little as possible, is that correct?
Yes, only use one connection. You don't even need the thread part, you could delete the "extends thread" part in ExampleBase and then just call run, however there's a thread.sleep in the run method and you would have to fix the logic. I don't know what your purpose is so it's hard to tell you what to do.

I wrote a very simple 1 file, console based program in the files section under java.



Maybe that will be easier to understand, it's also a netbeans project.

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