Best Python Framework for IB

Discussion in 'Automated Trading' started by hurricane_sh, Oct 16, 2019.

  1. I just discovered (very happily) there are many Python frameworks for IB, which ones are best for back test and automated trading?

    A good framework IMO should be:

    1. Open source is preferred.
    2. A long development history. I don't want to learn a system that's abandoned soon.
    3. Widely used with a big developer base.
    4. A community such as a forum is a big plus.
    5. Robust, flexible, etc.
    6. Back-test is more important than live trading for me at the stage.
     
    Last edited: Oct 16, 2019
  2. gaussian

    gaussian

    Hate to break it to you but...

    Write your own, don't trust code that you expect to pass order/financial information through that is owned by someone else.

    If you don't want to go this route, download a copy of the repository (do not clone) and audit every single line of the repository looking for potential information leaks.

    Don't believe that you should take it this seriously? Have a look at what has happened with other package managers:

    https://news.softpedia.com/news/nod...rable-to-malicious-worm-packages-502216.shtml

    https://blog.reversinglabs.com/news...ealing-user-credentials-on-the-npm-repository

    https://www.bleepingcomputer.com/ne...libraries-found-on-pypi-python-package-index/

    https://haacked.com/archive/2018/11/28/package-manager-trust/


    Make sure you understand your threat surface, isolate and audit any code that financial data goes through, and make your judgements from there. This isn't a case where you can fall back on something like Stripe/PayPal/etc to protect you from cases where your software caused (or caused to you) financial harm. If a malicious actor gets a hold of your IB account you are absolutely hosed in every sense of the word.

    To give you a sense of time commitment as a professional developer I wrote an IB integration (minus order passing) in a weekend with a 6 pack of my favorite beer. It's not hard, and it's good to know your API. I privately host a copy of the IB API (from their website) pegged to a release that I trust and build code on that. That is my only threat surface, and I don't really have much to worry about if it's only IB's official API that is a dependency my code relies on.

    EDIT:

    If you or anyone else has any questions on some of the more confusing bits of the IB API (in particular the three thread model they use) just send me a PM.
     
    Last edited: Oct 16, 2019
  3. Many thanks for your reminder, gaussian! It never occurred to me that my account could be compromised, that's definitely something serious. I'm completely new to Python and trading-related programming, I really want to have something running asap as I have dwelt on selecting a platform for too long.
     
  4. gaussian

    gaussian

    You may want to go simpler then. Trading isn't a great way to learn to program.

    Sierracharts comes to mind. They have a C# based programming language and an EasyLanguage programming language. If your strategies are chart-based you may be better serviced by one of these packages to get up and running quickly. They cost money (Sierracharts is around $1500 last I checked) but you're paying for a fully working fool-proof way to get automating trading immediately.

    If you are serious about Python programming your own API integration with be frustrating but rewarding. Choose your battles. If I were you I'd probably go with Sierracharts (unless you want to automate options trading or something).
     
    hurricane_sh likes this.
  5. Thanks, I did create an account with TradeStation, also checked out MetaTrader5 and AmiBroker, they are all seem to be good options. But I don't want to go the easy way, I think Python is the best option, especially there are frameworks that can help me get going quickly.

    I was a long time C++/Java programmer, also had some PHP experience, I'm willing to learn Python for the long run. But I think sometimes in the future, I will also get familiar with non-Python tools, they are popular for good reasons.
     
    Last edited: Oct 16, 2019
  6. Currently I'm looking at these frameworks, may select one with a quick glance.

    IBridgePy
    zipline-live
    QTPyLib
    pysystem trade
    backtrader
    PyAlgoTrade
     
  7. As the creator of pysystemtrade I can tell you that:

    - there is no malware in it - honest!
    - it doesn't yet have support for automated trading, though that's something I hope to have time to add in the next 12 months or so
    - it's very much a part time project for one person and not a commercial product with handholding available
    - for that reason it's probably not suitable for a complete beginner

    pyalgotrade, backtrader, qtpylib are also hobby open source projects that probably aren't suitable for beginners, although to be fair most are more advanced and cleaner than pysystemtrade.

    If you want something that is closer to 'plug and play' with support then for pure backtesting I'd recommend zipline. I haven't used zipline-live (which is also a hobby project) which you'd need to automated your trading. IBBridgePy is a bit of a black box to me so can't comment on that.

    GAT
     
    blueraincap and hurricane_sh like this.
  8. Wow, thanks a lot for your comments, GAT! Very glad to hear the insight from one of the creators. Just downloaded IBBridgePy.
     
    Last edited: Oct 16, 2019
  9. d08

    d08

    I'm also writing my own backtester at the moment but if you're completely new to Python, it will take a long time. You can get something basic that works but to build the features is time consuming and you'll most likely make bad structural decisions which are hard to remedy later.
     
  10. That sound's about right (although I'd personally allow 3 bottles of wine as I'm not a big beer drinker), but the order passing and associated processing is the bit that takes a lot longer to get right.

    That's a good idea, hadn't considered that.

    GAT
     
    #10     Oct 16, 2019
    gaussian, d08 and hurricane_sh like this.