1

I'm trying to get my account's total net liquidation amount. This is essentially the total amount in my portfolio of all positions, plus cash. However, the enclosed code is as close as I can get. I can then manually obtain it from the data below:

library(IBrokers)
tws <- twsConnect()
test<-reqAccountUpdates(tws)
test

I get the following data:

  AccountCode                      XXXX              
  AccountOrGroup                   XXXX      USD     
  AccountReady                     true                  
  AccountType                      PARTNERSHIP           
  AccruedCash                      0             USD     
  AccruedCash.S                    0.00          USD     
  AccruedDividend                  0.00          USD     
  AccruedDividend.S                0.00          USD     
  AvailableFunds                   1478.69    USD     
  AvailableFunds.S                 1478.69    USD     
  Billable                         0.00          USD     
  Billable.S                       0.00          USD     
  BuyingPower                      9812.27    USD     
  CashBalance                      1478       USD     
  CorporateBondValue               0             USD     
  Currency                         USD           USD     
  Cushion                          1                     
  DayTradesRemaining               -1                    
  DayTradesRemainingT.1            -1                    
  DayTradesRemainingT.2            -1                    
  DayTradesRemainingT.3            -1                    
  DayTradesRemainingT.4            -1                    
  EquityWithLoanValue              1478.69    USD     
  EquityWithLoanValue.S            1478.69    USD     
  ExcessLiquidity                  1478.69    USD     
  ExcessLiquidity.S                1478.69    USD     
  ExchangeRate                     1.00          USD     
  FullAvailableFunds               1478.69    USD     
  FullAvailableFunds.S             1478.69    USD     
  FullExcessLiquidity              1478.69    USD     
  FullExcessLiquidity.S            1478.69    USD     
  FullInitMarginReq                0.00          USD     
  FullInitMarginReq.S              0.00          USD     
  FullMaintMarginReq               0.00          USD     
  FullMaintMarginReq.S             0.00          USD     
  FundValue                        0             USD     
  FutureOptionValue                0             USD     
  FuturesPNL                       0             USD     
  FxCashBalance                    0             USD     
  GrossPositionValue               0.00          USD     
  GrossPositionValue.S             0.00          USD     
  IndianStockHaircut               0.00          USD     
  IndianStockHaircut.S             0.00          USD     
  InitMarginReq                    0.00          USD     
  InitMarginReq.S                  0.00          USD     
  IssuerOptionValue                0             USD     
  Leverage.S                       0.00                  
  LookAheadAvailableFunds          1478.69    USD     
  LookAheadAvailableFunds.S        1478.69    USD     
  LookAheadExcessLiquidity         1478.69    USD     
  LookAheadExcessLiquidity.S       1478.69    USD     
  LookAheadInitMarginReq           0.00          USD     
  LookAheadInitMarginReq.S         0.00          USD     
  LookAheadMaintMarginReq          0.00          USD     
  LookAheadMaintMarginReq.S        0.00          USD     
  LookAheadNextChange              0                     
  MaintMarginReq                   0.00          USD     
  MaintMarginReq.S                 0.00          USD     
  MoneyMarketFundValue             0             USD     
  MutualFundValue                  0             USD     
  NetDividend                      0             USD     
  NetLiquidation                   1478.69    USD     
  NetLiquidation.S                 1478.69    USD     
  NetLiquidationByCurrency         1479       USD     
  OptionMarketValue                0             USD     
  PASharesValue                    0.00          USD     
  PASharesValue.S                  0.00          USD     
  PostExpirationExcess             0.00          USD     
  PostExpirationExcess.S           0.00          USD     
  PostExpirationMargin             0.00          USD     
  PostExpirationMargin.S           0.00          USD     
  PreviousDayEquityWithLoanValue   1478.69    USD     
  PreviousDayEquityWithLoanValue.S 1478.69    USD     
  RealCurrency                     USD           USD     
  RealizedPnL                      0             USD     
  SegmentTitle.S                   US Securities         
  StockMarketValue                 0             USD     
  TBillValue                       0             USD     
  TBondValue                       0             USD     
  TotalCashBalance                 1479       USD     
  TotalCashValue                   1478.69    USD     
  TotalCashValue.S                 1478.69    USD     
  TradingType.S                    PMRGN                 
  UnrealizedPnL                    0             USD     
  WarrantValue                     0             USD     

I also tried messing with twsPortfolioValue, but wasn't able to get it to work.

Ideally, I'd like to specify the field, instead of reading X number of records down. IE I want to specify "NetLiquidation" as opposed to "row 58."

Any thoughts? Thank you so much for your help!

Trexion Kameha
  • 3,362
  • 10
  • 34
  • 60
  • If you would instead post `str(test)` you might get a better answer. – IRTFM Dec 02 '14 at 22:12
  • Thanks BondedDust. Not sure how that is helping. Can you explain? – Trexion Kameha Dec 03 '14 at 00:12
  • We don't know what the object `test` really is. You've only shown its `print()`-representation. – IRTFM Dec 03 '14 at 00:27
  • BondedDust is right. No one would possibly be able to guess what type of object you're working with unless they happen to have an IB account and have IBrokers installed and configured. That said, I can understand being cautious about posting sensitve data, and the output of `dput(test)` or `str(test)` might not be simple to obfuscate. – GSee Dec 03 '14 at 03:13

1 Answers1

1

test is a list. The first component is an object classed as eventAccountValue, which has its own print method to make it look like a data.frame. However, if you call unclass(test[[1]]), you'll see that it's really just a list.

So, you can access the "NetLiquidation" component of the first component of your test object like this

test[[1]][["NetLiquidation"]]
#    value*   currency 
# "1478.69"      "USD" 

*value changed to match OP's value.

GSee
  • 48,880
  • 13
  • 125
  • 145
  • This is great. I have never seen that type of syntax so this is definitely helpful. Thank you. Do you know how I can extract just the numeric value out of these data? – Trexion Kameha Dec 03 '14 at 15:21
  • something like this? `as.numeric(test[[1]][["NetLiquidation"]][["value"]])` or `as.numeric(test[[1]][["NetLiquidation"]][[1]])`. untested. – GSee Dec 03 '14 at 16:07