2014-12-02 94 views
1

我试图获取我帐户的净清算总金额。这实际上是我所有职位投资组合的总金额,加上现金。然而,附上的代码尽可能的接近我所能得到的。我可以手动从下面的数据中获得它:盈透证券使用IBrokers API的当前帐户价值

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

我得到以下数据:

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  

我也试图与twsPortfolioValue搞乱,但无法得到它的工作。

理想情况下,我想指定该字段,而不是读取X个记录。 IE我想指定“NetLiquidation”而不是“第58行”。

有什么想法?非常感谢你的帮助!

+0

如果你想改为发布'str(test)',你可能会得到更好的答案。 – 2014-12-02 22:12:37

+0

感谢BondedDust。不知道这是如何帮助。你可以解释吗? – 2014-12-03 00:12:44

+0

我们不知道“测试”对象究竟是什么。你只显示它的'print()' - 表示。 – 2014-12-03 00:27:59

回答

1

test是一个列表。第一个组件是归类为eventAccountValue的对象,它具有自己的打印方法,使其看起来像data.frame。但是,如果您拨打unclass(test[[1]]),您会发现它实际上只是一个列表。

所以,你可以访问你的test对象的第一个组成部分的“NetLiquidation”组件等而改变,以配合OP的价值这个

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

*值。

+0

这太好了。我从来没有见过这种类型的语法,所以这绝对有帮助。谢谢。你知道我如何从这些数据中提取数值吗? – 2014-12-03 15:21:57

+0

这样的事情? as.numeric(test [[1]] [[“NetLiquidation”]] [[“value”]])或as.numeric(test [[1]] [[“NetLiquidation”]] [[1] ])'。未经测试。 – GSee 2014-12-03 16:07:20

+0

完美,谢谢Gsee! – 2014-12-03 17:20:14