Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reqAccountUpdates portfolioValue returning wrong results #30

Closed
fmair opened this issue Apr 26, 2021 · 6 comments
Closed

reqAccountUpdates portfolioValue returning wrong results #30

fmair opened this issue Apr 26, 2021 · 6 comments
Assignees
Labels

Comments

@fmair
Copy link

fmair commented Apr 26, 2021

Description

I have a position of 10 SPY shares in my paper trading portfolio. They were bought at 411.55 and now have a market value of 4173.40 (roughly). When I run reqAccountUpdates and twsPortfolioValue the results do not match. It seems like all entries are shifted by one row. (see entries below "portfolioValue" in the list below). Also the output for twsPortfolioValue is not correct.

Edit: I just tested it and the functions show the expected behavior when using the current CRAN version IBrokers_0.9-12.

Expected behavior

reqAccountUpdates should return the current positions of the portfolio including position sizes.

Minimal, reproducible example

x <- reqAccountUpdates(conn, subscribe = T, acctCode = "1")
> twsPortfolioValue(x, zero.pos=T)[2, ]
  local sectype marketValue averageCost return position realizedPNL unrealizedPNL
2   SPY     STK     417.344          NA     NA       NA       57.91      411.5534
> x[[2]][[2]]
List of 2
 $ contract      :List of 17
  ..$ conId          : chr "756733"
  ..$ symbol         : chr "SPY"
  ..$ sectype        : chr "STK"
  ..$ exch           : chr "ARCA"
  ..$ primary        : chr "ARCA"
  ..$ expiry         : chr ""
  ..$ strike         : chr "0"
  ..$ currency       : chr "USD"
  ..$ right          : chr "0"
  ..$ local          : chr "SPY"
  ..$ multiplier     : chr ""
  ..$ combo_legs_desc: chr ""
  ..$ comboleg       : chr ""
  ..$ include_expired: chr ""
  ..$ secIdType      : chr ""
  ..$ secId          : chr ""
  ..$ tradingClass   : chr ""
  ..- attr(*, "class")= chr "twsContract"
 $ portfolioValue:List of 7
  ..$ position     : num NA
  ..$ marketPrice  : num 10
  ..$ marketValue  : num 417
  ..$ averageCost  : num 4173
  ..$ unrealizedPNL: num 412
  ..$ realizedPNL  : num 57.9
  ..$ accountName  : chr "0.0"

Session Info

I've loaded some private packages, hence I'd prefer not to share my session info. However, these don't interfere with IBrokers. I'm using Windows 10 x64 and running IB TWS Build 981.2z, Apr 13 2021.

IBrokers_0.10-1
@fmair
Copy link
Author

fmair commented Apr 13, 2022

The problem persists with the current CRAN-version 0.10-1 and TWS Build 10.15.1d, Apr 5, 2022 and comes from the way reqAccountUpdates handles the messages (msg[12]).

@fmair fmair mentioned this issue Apr 28, 2022
@joshuaulrich joshuaulrich self-assigned this May 2, 2022
@joshuaulrich
Copy link
Owner

Just pushed a commit that should fix the issue. Please test and let me know! You can install the version on this branch by using:

remotes::install_github("joshuaulrich/IBrokers@30-reqAccountUpdates-portfolioValue")

@Camilo-Mora
Copy link

Perfect. I just verified and the problem is fixed. Where was the bug?. Thank you Josh.

@joshuaulrich
Copy link
Owner

@Camilo-Mora Take a look at the commit diff and message: 970fca2

@fmair
Copy link
Author

fmair commented May 3, 2022

Just pushed a commit that should fix the issue. Please test and let me know! You can install the version on this branch by using:

remotes::install_github("joshuaulrich/IBrokers@30-reqAccountUpdates-portfolioValue")

I can confirm that it is working again. Thanks for the fix!

@joshuaulrich
Copy link
Owner

Thanks for testing, @Camilo-Mora and @fmair!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants