positions | R Documentation |
Fetch positions for all accounts.
positions(port = 7496, clientId = 1,
contractFields = c("conId", "localSymbol", "currency"),
verbose = TRUE)
port |
integer |
clientId |
integer |
contractFields |
character; contract information to include, see Examples |
verbose |
logical |
Fetch current positions (possibly for more than one account) for the running TWS session.
A data.frame
with columns account
,
position
and avgCost
, and contract data
specified by argument contractFields
.
There are at least two attributes:
a data.frame with columns account
,
currency
and value
a list of contracts
Enrico Schumann
https://www.interactivebrokers.com/campus/ibkr-api-page/twsapi-doc/
ib_hist_data
## Functions require an account with Interactive Brokers
## and a running TWS.
positions(port = 7496)
## contract data
if (requireNamespace("rib"))
names(rib::Contract)
p <- positions(port = 7496,
contractFields = c("conId", "localSymbol", "strike",
"lastTradeDateOrContractMonth"))
## show cash holdings
attr(p, "CashBalances")
## get contract details for first position
p[1, ]
contract_details(attr(p, "Contracts")[[1]])
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.