Python code to access IB "FlexStatement" service.

Discussion in 'Interactive Brokers' started by ZenEng, Jan 2, 2007.

  1. ZenEng

    ZenEng

    For those of you who use Python, read on. I don't expect to provide basic instruction in using Python but will provide a few links of prerequisites to use the code.

    I will include code to download and process the XML data from the IB website to the local disk and code to do a simple summation of commissions paid in separate posts.

    See also this thread for a discussion of the FlexStatement improvements needed:
    wip put link here.

    Prerequisites:

    - You will need to install Python if you don't have it. This is really beyond the scope of this discussion but links include:
    - http://www.python.org
    - http://www.cygwin.com (which is what I used on Windoze)
    - http://activestate.com/python.plex
    - http://www.linuxjournal.com/article/3882 Look here rather than asking my why I use Python.

    - This code uses the "mechanize" package to connect to the web site:
    - http://wwwsearch.sourceforge.net/mechanize/

    - And uses "BeautifulSoup" to simplify access to the XML data in a compact way:
    - http://www.crummy.com/software/BeautifulSoup/

    See subsequent posts for code (and feel free to join in and post your own!).
     
  2. ZenEng

    ZenEng

    Here is the code to download your statements into a folder "xml" in the current directory.

    Replace report numbers with the ones that you created with FlexStatement.
     
    • dl.txt
      File size:
      4.6 KB
      Views:
      192
  3. ZenEng

    ZenEng

    Attached is some example code on how to create a dumb little report that summarizes accounts, account equity (Note that IB's implementation doesn't include accrued interest!!!), and commissions by symbol with gross settlement amounts.

    You can play with this to do a variety of things. I think that the ideal spec is to create a report something like the one that FuturesTrader71 gave in this post:
    http://www.elitetrader.com/vb/showthread.php?s=&postid=614275#post614275

    One lack on the download is that trades don't include the order reference from the originating system...
     
    • rep.txt
      File size:
      2.7 KB
      Views:
      89
  4. ZenEng

    ZenEng

  5. fleance

    fleance

    I have created something similar in Java.

    I really like the IB FlexStatements because the XML format is easy to manipulate programatically.

    But the last time I checked, they are only archiving the last 45 days of trades, so if you forget to download them for a couple months, then you will have a hole.

    They should really archive the trades for 2 years or more.

    I have been using TradeLog commerical software to create monthly and annual trade reports. I'm looking to replace that by using the Flex Statements reports plus my java code to generate some reports in CSV format and then import into a reporting tool to finish it.
     
  6. ZenEng

    ZenEng

    fleance, care to post your code also?

    This kind of technology is useful to share.

    I'm curious about the ratio of the number of lines of code between Java and Python implementations, though I'm sure your code does a lot more.