Beginner C++ question

Discussion in 'Programming' started by codeine, May 20, 2011.

  1. codeine

    codeine

    Hello, I am new to IB's API, and I have a beginner-level understanding of C++. (I'm mostly a Javascript/HTML oriented web-programmer)

    So.. some of my questions are very elementary.

    On page 24 of 140 of the Getting Started C++ API (pdf file) it mentions that you need an IDE that "supports Microsoft C++, as well as Microsoft Visual Basic and the Microsoft .NET framework."

    I have been tinkering with MS Visual C++ 2010 Express, and a few other compilers as well. Borland C++ 5.5 (available from Embarcadero). In the past I used Metrowerks CodeWarrior, but I no longer have access to that platform.

    The question I have is: is it necessary to use a MS Visual Studio platform? Or is it just the sample program that requires MS Visual Studio? How does the API use/interact with MFC? (whether or not that is a valid question, I don't know)

    Is it possible to write a simple console-based/command-line program to interact with the API and use TWS for visualization/GUI?

    Does the API include all the libraries necessary for it's own execution? (For example, could I write a program, and compile with Borland C++ 5.5, provided that I include TWS API's libraries?) Or are there other MS libraries that are necessary?

    Thanks in advance, everyone. I realize these are some very basic/rudimentary questions, and I appreciate any constructive feedback and/or re-direction.

    Thanks!
     
  2. VS is just the most powerful environment. Probably the best choice to start. (No need to be masochistic ;-)) with c++, can use c# as well and with better productivity).

    Tom
     
  3. LeeD

    LeeD

    It means that it requires Microsoft Windows API (such as file Windows.h) and possibly a few Microsoft laguage extensions for C++.

    Note that most commercial C++ compilers include the original Microsoft headers. (Borland C++ includes MFC too.) Free compilers like gcc via MinGW may include independedntly reconstructed versions of Microsoft Windows headers but wouldn't have MFC.

    MFC is only an object-oriented GUI library. If the application doesn't have GUI, it probably doesn't use MFC. If an application without GUI does use MFC, it's probably for simple things like timers that can be easily replaced with standard components.


    Yes, of course. The problem is TWS API offers access to trading information and market data. You can't use it. for example, to add new buttons to TWS windows. So, the input and output fo such an application will be text...

    TWS API does NOT include all necessary API libraries. In particular, it doesn't include Windows sockets libraries that are necessary for communication with TWS.

    However, as I mentioned above, commercial compilers normally include the necessary libraries, and free applications improvise to offer similar functionality.
     
  4. why dont you just use ib's java api with eclipse ide. A lot less headache...
     
  5. codeine

    codeine

    Hey! I really appreciate all the feedback. Exactly the kind of insight I'm looking for..

    VS is just the most powerful environment. Probably the best choice to start. (No need to be masochistic ;-)) with c++, can use c# as well and with better productivity).

    Hehe.. I know what you mean. I have an OCD thing going on which drives me to understand things at their deepest level. It probably also means I submit myself to more pain than is really necessary. Point taken..

    I suggest you take a look at the IB API forum.

    Definitely going to check the IB forum out.

    It means that it requires Microsoft Windows API (such as file Windows.h) and possibly a few Microsoft language extensions for C++.

    Ok. I'm guessing that the socket-interface itself (TwsSocketclient.lib ?) is the part that requires the MS Windows API. Perhaps?

    MFC is only an object-oriented GUI library. If the application doesn't have GUI, it probably doesn't use MFC. If an application without GUI does use MFC, it's probably for simple things like timers that can be easily replaced with standard components.

    I suspected this, but it was really just a guess. Thanks for clarifying that.

    You can't use it, for example, to add new buttons to TWS windows. So, the input and output for such an application will be text...

    Ok, I just meant I want to use TWS to visualize the orders I was executing through the API. (If I executed automated orders) The rest of the program would be automated, inquiring about price/volume/statistics on a pre-defined list of stocks and writing results to a file. But I see what you mean about not having a GUI - you wouldn't be able to interact with your program to control it's function.

    TWS API does NOT include all necessary API libraries. In particular, it doesn't include Windows sockets libraries that are necessary for communication with TWS. However, as I mentioned above, commercial compilers normally include the necessary libraries, and free applications improvise to offer similar functionality.

    This is exactly what I was wondering - standard windows-interface components that are required for API operation but normally supplied with a decent implementation. I think I get it now.

    why dont you just use ib's java api with eclipse ide. A lot less headache...

    Hmm.. Perhaps I will look into this as well. I suppose I jumped into the C++ idea because it was a language I had dabbled with before. Plus, I'm already 340 pages deep into C++ Primer Plus. And Ivor Horton's Beginning Visual C++ 2010 is in the mail. I'm pretty much committed to learning C++, I guess.

    Thanks guys! Any further posts appreciated, too.
     
  6. LeeD

    LeeD

    The actual API is a part of Windows. So, it comes with Windows license. However, the headers that describe the API (including definitions of specialised data types etc) are subject to copyright on their own.

    So, TwsSocketclient.lib communicates with Widnows directly where it needs it and doesn't need these headers. However, TwsSocketclient.lib it uses data types defined in Microsoft header files.
    WHat I meant to say is you can't programmatically add any new visaul components to TWS at all. If you want to watch positions and PnL TWS is an adequate solution. However, if you want to see volatilities or some other calculated values there is no interface to display them in TWS.

    Due to this limitation, for peopl who don't like java the leading solution is .NET - due to sheer ease of creating graphic interfaces.

    If you want to stick with C++ but use Microsoft technology on the cheap, remember free Visaul C++ Express doesn't come with MFC but it comes with .NET visual components, same as C# or VB.NET.
     
  7. To compile their examples, yes you need VS. But to successfully write an automated system, you don't specifically need VS. I use mingw32 and cross-compile binaries from Linux when I need something to interact with TWS on Windows.

    If you insist on using Visual C++, avoid the Express editions. If you switch brokers and want to take your code elsewhere (like Sterling, for example), you'll have issues using Express to successfully talk to and work with their ActiveX object.

    Yes. Try their PosixTestClient binary and you will find that you can do this.

    PosixTestClient lets you do this, no Microsoft-specific libraries needed.

    Glad to (attempt to) help.

    My personal bias, for what it's worth, is to just use the GNU tools. Try not to get too bound to a given platform, because you'll find that, in this business, you occasionally want to switch brokers for some reason or another. Try to stay as vendor and platform neutral as possible if you're going so far as to write C++ code.
     
  8. LeeD

    LeeD

    Strongly disagree. You can always evolve from an Express edition. All code and projects created in Express editions are completely reusable in matching "paid-for" editions without limitation.

    The only reasons not to use Express editions are:
    1) if you already own a license for a paid-for edition, or
    2) you require features unavailable in Express editions such as using Visual Assist X or revision control.
     
  9. You're right, except it's a hassle. The express edition doesn't even have MFC, not just those other features. You always find some vendor uses some fancy Windows toolkit or library, or some COM piece (TradeStation is COM heavy, Sterling's ActiveX, IB's example uses MFC I think, and I think LASER has some advanced library that uses some MFC (I don't remember)) It gets pretty annoying quickly.
     
    #10     May 22, 2011