Writing a GUI to TWS in C# part 4

Discussion in 'Trading Software' started by Fredrik99, May 18, 2006.

  1. Hello again!
    I am still writing on my GUI to TWS. I have posted questions to this forum every now and then, and so far I have got some really
    useful responses from people here.

    Now I have come to a point where I need a way to restart the TWS from my own app.
    I dont see any methods for this in the axTws1.

    Isn´t there a way to start other programs using



  2. Presumably you want to login, not just start TWS. The easiest way I have found is to do it in Java using 'jemmy' from http://www.netbeans.org. Jemmy is a package for automating Java Swing GUI test harness.

    If you need a code fragment I can provide one.
    It's only a few lines of code.
  3. If you use 'jemmy', will the automated login do it all for you, or do you also have to start TWS in a separate call?

    I am writing in C#, but I suppose there is some way I can solve
    this anyway.

    I am curious about that fragment. If you have the time, please post it!


  4. It starts TWS and logs in. You need all the appropriate jars in your classpath to run it. It's easier to build the thing in a Netbeans project and have it create a single jar containing jemmy, TWS - the lot.

    import org.netbeans.jemmy.*;
    import org.netbeans.jemmy.operators.*;
    public class TWSSupervisor
        public TWSSupervisor ()
                String [] params = new String [1];
                params [0] = "*** TWS Home Directory full path name";
                new ClassReference("jclient.LoginFrame").startApplication(params);
                JFrameOperator loginFrame = new JFrameOperator("Login");
                JTextFieldOperator userNameField = new org.netbeans.jemmy.operators.JTextFieldOperator (loginFrame);
                JPasswordFieldOperator passwordField = new org.netbeans.jemmy.operators.JPasswordFieldOperator (loginFrame);
                JButtonOperator loginButton = new JButtonOperator (loginFrame, "Login");
                loginFrame.requestFocus ();
                userNameField.requestFocus ();
                userNameField.typeText ("edemo");  // USER NAME
                passwordField.requestFocus ();
                passwordField.typeText ("demouser"); // PASSWORD
                loginButton.requestFocus ();
                loginButton.push ();
            catch (Exception e) 
        public static void main(String[] argv) 
            new TWSSupervisor ();
  5. Thank you so much dcraig! I will study it carefully

  6. Not sure if you're aware but the twsapi group at Yahoo! has discussed many issues such as this in the past. There are also plenty of code samples that may be of use.

    Good luck.