IB API Portfolio

Discussion in 'Trading Software' started by Doobs789, Jan 9, 2014.

  1. Doobs789

    Doobs789

    This is probably a fairly simple question;

    I have very little experience with the IB API. Within their sample ActiveX Excel sheet there is the ability to download account and portfolio data from TWS. My question is; How can I separate this page and incorporate it into a new Excel workbook. I would like to be able to download my account positions, then run some other calculations using this data (option greeks, P/L, etc). I like the ability to click a button (macro) and get my current positions, as opposed to entering them manually. Thanks.
     
  2. Not sure if I understand correctly but I used to do this just by updating the latest portfolio info from IB (using their spreadsheet template you're referring to) and copy/pastevalue into a separate workbook for analysis (where I also kept historical portfolio snapshots for comparison - usually daily or after a sig change).

    You could fully automate that process but even if you didn't it should be much faster than entering each position manually. I can probably find some old samples if you'd like.
     
  3. Doobs789

    Doobs789

    Ok thanks. Yeah, I could copy/paste then run my numbers. I just like to have things automated (although it will probably save me 5 secs). Any sheets are appreciated.
     
  4. FXforex

    FXforex

    RE: copy/paste

    I'm not familiar with IB's API but there has to be a better way than copy/paste. I would think that you can export the data to a CSV file then import the CSV file into another software program, such as Excel.
     
  5. Doobs789

    Doobs789

    Basically, I want to know how to move the vb codes/modules into a new workbook. I have tried import/export, and other methods, but it doesn't work.
     
  6. I suppose TWSActiveX.xls and ThirdPartyFile.xls can run at the time.
    I think there are two solutions :
    1/ Merge both files (but it might not work):
    Copy/Paste the spreadsheets ‘General’,’Account’,’Portfolio’ from TWSActiveX.xls to ThirdPartyFile.xls
    Copy/Paste the modules present in the spreadsheets ‘General’, ’Account’, ’Portfolio’ from TWSActiveX.xls to ThirdPartyFile.xls
    Copy/Paste modules and class modules from TWSActiveX.xls to ThirdPartyFile.xls
    At this stage you should check modules are compatible (variables, functions, procedures from TWSActiveX and ThirdPartyFile should have different names).
    Try to run both applications at the same time: it may crash for various reasons…

    2/ An easy solution:
    Insert a new spreadsheet in ThirdPartyFile.xls
    Copy/paste ’Portfolio’ from TWSActiveX.xls to ThirdPartyFile.xls
    Rename this spreadsheet as ‘Portfolio’
    Next, you link the cells you want from ThirdPartyFile.xls to TWSActiveX.xls.
    For instance, click on cell A6 of [ThirdPartyFile.xls]Portfofio, insert ‘=’, click on cell A6 of TWSActiveX.xls>Portfolio
    Now in A6 you have ’=[TwsActiveX.xls]Portfolio!$A$6’
    Remove both ‘$’
    Now in A6 you have ’=[TwsActiveX.xls]Portfolio!A6’
    Copy/paste the formula in A6 for the range A6:S206

    Run TWSActiveX.xls i.e.
    General> Click ‘Connect to TWS Button’
    Account> Click ‘Request Account Updates’
    Now, you should have updates of your portfolio in TWSActiveX.xls and ThirdPartyFile.xls