IB API HOWTOs and Guidelines - For Beginners

Discussion in 'App Development' started by Butterfly, Nov 8, 2013.

  1. My 2 bytes..

    From what you've described, it's unclear what you're trying to achieve. Are you trying to build a research framework, automated trading system, or both within the same framework?

    It appears like OP is trying to explain basic functionality of the API. What you're asking with the submit, modify, cancel orders is how to build a reliable OMS/ATS.

    So let me ask you this.. what are your strategy constraints (this will dictate the technology required and design patterns)? Is it a HFT system? Are you just executing end of day? Non high-frequency intraday? I think you need to answer those questions before thinking about which language you want to code it up in.
     
    #31     Nov 12, 2013
  2. crmorris

    crmorris


    it's coded, been running for years. it's relatively high frequency (thousands of modifies daily). i would like to improve it -- port it to a framework that's faster, more stable, more productive.
     
    #32     Nov 12, 2013
  3. vicirek

    vicirek

    Where to go? good question at the right time;

    One potential headache with Windows is Windows platform future. Microsoft is abandoning desktop in favor of COM based Win RT with many limiting factors regarding developers, program interaction with machine. Win Rt is closed platform (no more installing hello world program on grandma computer).

    I use .Net but I am seriously looking at native C++ which by the way is getting second life with C++ 11 and also Win RT modern UI apps. As added bonus it is platform independent.

    Python; Why python? code is not simpler and getting it set up properly with packages takes time. For once Visual Studio 2013 has python IDE built in but adding modules is painful for unexperienced.
     
    #33     Nov 12, 2013
  4. FWIW I'm not a software engineer by profession or training. So this is more or less what I've hobbled together from friends who build automated trading systems for a living.

    Operating system should not matter, just whatever is easiest given your broker API.

    If milliseconds matter to you, then writing a production trading system in any scripting language (e.g. python) would be foolish IMO.

    Now I think the trade-off here is building your research infrastructure in R or Python. Then your trading framework in a proper programming language. Dev time under Java will generally be faster, but you'll need to deal with GC if you're doing HF.

    Now to answer your question about reliably submitting, modifying, and cancelling orders. From the sounds of things, you're doing some kind of liquidity providing strategy, as such you probably want to use an event-driven design pattern.

    I think explaining everything in depth is beyond what I can type up here. However, you basically need to keep track of order states (treat it as a FSM) within your strategy class. Here's a code snippet from my system..

    Code:
    public void doOnNewOrderAccepted(final ClOrdId clOrdId, final OrderSpecification order) {
        if (order.getTradeType() == TradeType.SELL || order.getTradeType() == TradeType.SHORT) {
            this.askClOrdId = clOrdId;
            this.currentAsk = order;
            this.pendingAskClOrdId = null;
            this.pendingAsk = null;
        } else {
            this.bidClOrdId = clOrdId;
            this.currentBid = order;
            this.pendingBidClOrdId = null;
            this.pendingBid = null;
        }
    }
    
    Then just build out methods for all other possible actions (e.g. doOnAsk, doOnBid, doOnFill, doOnCancelRejected) and link the logic together.

    For a non HF system, it makes more sense to build out a StrategyManager then have Strategy instances talk to it. The method explained above is fairly computationally intensive.
     
    #34     Nov 12, 2013
  5. I don't understand why people keep saying python modules are difficult to install. It's incredibly simple just use either pip or easy_install. And the code is far simpler than C++ or Java. I think for a basic OMS trading EOD strats, Python would be great.
     
    #35     Nov 12, 2013
  6. rwk

    rwk

    Some of my questions are slightly off-topic regarding HowTo for beginners. My point was that I like accessing the TWSAPI via the ActiveX mostly because it's supported by IB, but also because I find it easy to use and efficient. My interest is in trading, not in software engineering.

    Unfortunately, the ActiveX kind of locks me into Windows unless I can run it on Linux + Wine. The post by crmorris pretty well summarizes my situation. I have no compelling need to change language or OS right now, but I am trying to avoid future obsolescence or worse, forced upgrade on short notice.

    I agree that Java would be a good choice if I were starting from scratch. Learning a new programming language or OS are not a trivial exercises. I'm struggling with whether either is worth the effort.

    I think OS, programming language, and API are all intertwined. But I couldn't agree more that trading logic is an entirely separate topic requiring a different mindset.
     
    #36     Nov 12, 2013
  7. vicirek

    vicirek

    This is exactly why I tried python for rich libraries and plotting. However, it still takes more work than I would expect to switch to Python. Looking at the Python code I do not see much advantage over what I am doing in .Net.

    But the bottom line is that I was looking for something super super easy and tried few book examples in VS2013 but I am getting many errors of missing this or that for particular library so I gave up with that project. What I will do for now is to translate python code to .net and when I have more time to learn Python I give it another try.
     
    #37     Nov 12, 2013
  8. I suggest just installing cygwin (if you're using windows), then using pip/easy_install for all module installs. Then use ipython for your interpreter/ide.
     
    #38     Nov 12, 2013
  9. vicirek

    vicirek

    Thank you. I was not aware such tools exist.

    I just started looking at Python because books on math/data analysis/science with python example code are better than matlab books not mentioning the cost of owning matlab.
     
    #39     Nov 12, 2013
  10. Butterfly

    Butterfly

    you couldn't be further from the truth,

    Python is extremely simple to program, it is what Java used to be before the framework non-sense boom, installing packages couldn't be simpler, just move the proprietary libs into your Python lib path if you don't want to use an "installer" or pipe.

    Using Visual Studio for Python is asking for trouble, it's an overbloated system that will make simple tasks very complicated. It's the same with Eclipse for Java and other code studio solutions. It's not useful for 90% of the development work out there, but for some reasons, developers can't get enough of those silly IDE. Eclipse is a bit of an exception as it has become a RCP for Java, basically more than a Developer Studio, it's an UI style with a deployment framework.

    For the record, I code all my Python things in "vi" or notepad :p
     
    #40     Nov 12, 2013