ribrokers

IBrokers - Download all position information


I am using the IBrokers API in R to try to download my current positions in my portfolio on Interactive Brokers. However, I'm having trouble downloading the information by following the API documentation.

I can get this far with the following. This downloads my account information, but it's not a desireable format.

tws <- twsConnect()
reqAccountUpdates(tws)

I trade using the following, but it doesn't work.

twsPortfolioValue(tws)

Ideally, I want a data frame that has the following fields: ticker, shares, execution price.

Is anyone familiar with this API?

Thank you!


Solution

  • You're passing a twsconn object to twsPortfolioValue, but the function needs the output of reqAccountUpdates as its input, as explained in the Details section of ?twsPortfolioValue

    Try this:

    ac <- reqAccountUpdates(tws)
    twsPortfolioValue(ac)