Calling TWS ActiveX from C#

Discussion in 'Trading Software' started by nitro, Oct 7, 2003.

  1. nitro


    Has anyone a very simple program that they are willing to share (a simple project/solution?) that shows how to get C# talking to the TWS API using the ActiveX control ?

    I have gotten all the example programs that come with the TWS API to work (VB and VC++.) I have also gotten C# to talk to many ActiveX controls, and while I can get the C# program to compile and link, I cannot even get the TWS ActiveX connect function to work! (I get an exception) :( :(

    nitro :confused:
  2. Hi nitro,

    I gave up on C# and VB.NET about two years ago. Although both were only in a late beta state at that time, things reminded me of the hassle I had to go through with the Visual.x's (C++ & vb) before anything stable became available. Nitro, I cannot be of any help, but reading your post reminds me of getting M$ samples to work but having to spend weeks to find workarounds to solve bugs in my real stuff.

    I must say that after many years VC++ v6 and vb6 run reasonably well. Documentation is still haphazard and inconsistent. As Activex is based on DCOM (COM, COM+, etc) I recall vividly the misery I used to encounter in this area before things finally became passable.

    I am still doing a lot of work with my VC++ and vb6 tools but I am definitely migrating away from this mess. So my advise would be, nitro, do not become an M$ laboratory rabbit, stick to the older stuff that works. It might save you from having to post something like this one in a couple of years.

  3. NinjaTrader_Dierk

    NinjaTrader_Dierk ET Sponsor

    I know that there are occational problems using the ActiveX control in .Net envronment (see IB API Forum, search for "stop sending ticks" or my user name). Bad I havn't any experience using C# and TWS ActiveX.

    Anyway: Due the problems using the ActiveX component I decided to write a native IB .NET interface and publish it. This could be helpful, if you are a bit patient ...:D
  4. My main programing platform is C#, and I have developed Automatated Trading System using TWS ActiveX. It's been for a while probably 2 years now. I would be happy to share my works and tips with anyone here who are interested in.
    The only issue is that I often feel the posts by nitro is arrogant, and in fact he attacked me personally before. Probably my HN was different, which I lost password-username combination at a PC trouble.:(
  5. Nitro,

    Have you checked out this example in VB.NET? I know it's not C#, but at least it is an example in the .NET framework, so maybe it will give you an idea of how to get the Ax control working. .Net Code/

    Also, if sockets is your thing you could simply convert the rest of the C++ socket implementation to C# and bypass the ActiveX control completely (arguably a lot of work, but this is another possibility). I converted the quote reporting portion to VB6 (most of the real meat of the code is Windows APIs so it shouldn't be too hard to convert over to C#), and that sample is available on: Code/Advanced VB/

    There are also undoubtedly some folks on the TWSAPI list who have done things in C#. Maybe posting your request on that list could elicit some code samples from C# developers?
  6. nitro



    Thanks for the warnings. I have used C# to write some very powerful apps. My experience differs from yours somewhat.

    One thing I really hate about C# is that there is no clean way to call old style C++ libraries/dll's - you have to go thru this Interop crap. I should just be able to say:

    extern unmanaged C { //nitro invented this syntax
    #include oldstyle.h

    And the compiler should take care of the rest.

    nitro :mad:
  7. nitro



    I will be very interested in what you come up with. Please keep me posted.

  8. nitro



    Thanks for even responding - I am somewhat arrogant, Gawd knows I am do not mean to be, but I cannot help myself sometimes.

    nitro :(
  9. nitro



    YOU RULE THE FREAKING MARKETS. This is all I needed. What is funny is that I tried this and it did not work the first time! :confused:

    Thanks a MILLION.

    :D :D :D
    :D nitro :D
    :D :D :D
    #10     Oct 7, 2003