ibkrcp provides a lightweight R interface to the Interactive
Brokers Client Portal REST API. It covers the four areas you need
for programmatic trading:
ibkrcp communicates with the IBKR Client Portal Gateway
— a lightweight Java process that must be running locally and
authenticated before any function in this package will work.
Setup steps:
Download the Client Portal Gateway from the IBKR API page
Unzip and start the gateway from a terminal:
java -jar root/run.jar root/conf.yamlOpen https://localhost:5000 in your browser and log
in with your IBKR credentials
Confirm the session is live before making any API calls
The gateway exposes the REST API on
https://localhost:5000 and uses a self-signed certificate.
ibkrcp disables SSL verification for all requests — this is
intentional and necessary for localhost communication.
Sessions time out after approximately 5 minutes without activity.
Call ibkr_tickle() regularly to keep the session alive.
The sections below walk through a full end-to-end workflow: starting the session, finding an instrument, fetching price history, and placing an order.
Always start by confirming the gateway is running and authenticated:
library(ibkrcp)
# Verify the session is alive and authenticated — stops with an error if not
ibkr_tickle()
# Check the raw authentication status
ibkr_auth_status()If the session has timed out but the gateway is still running, re-authenticate without restarting the gateway:
# List all accounts associated with your login
accounts <- ibkr_get_accounts()
accounts
#> account_id type currency alias
#> 1 U1234567 INDIVIDUAL AUD Paper Trading
account_id <- accounts$account_id[1]
# High-level portfolio summary: cash, net liquidation, available funds
ibkr_get_summary(account_id)
# Current open positions
positions <- ibkr_get_positions(account_id)
positions
#> conid symbol position mkt_price mkt_value avg_cost unrealised_pnl currency
#> 1 123456789 VGS.AX 100 120.50 12050 115.00 550 AUDIBKR identifies every instrument by a numeric contract ID (conid).
Use ibkr_search_contracts() to find the conid for an
ASX-listed ETF:
# Daily OHLCV bars for the past year
prices <- ibkr_get_price_history(conid, period = "1y")
head(prices)
#> date open high low close volume
#> 1 2025-05-01 119.00 121.00 118.50 120.50 50000
#> 2 2025-05-02 120.50 122.00 119.80 121.30 48000
# Available period strings: "1m", "3m", "6m", "1y", "2y", "3y", "5y"
prices_3m <- ibkr_get_price_history(conid, period = "3m")Use the trading schedule to distinguish trading days from public holidays before submitting orders:
ibkr_place_order() places a DAY market order and
automatically handles any confirmation prompts returned by the API:
| Function | Description |
|---|---|
ibkr_tickle() |
Confirm session is alive and authenticated |
ibkr_auth_status() |
Get raw authentication status |
ibkr_reauthenticate() |
Request session re-authentication |
ibkr_get_accounts() |
List all accounts |
ibkr_get_summary() |
Portfolio summary for an account |
ibkr_get_positions() |
Open positions for an account |
ibkr_search_contracts() |
Search for contracts by symbol |
ibkr_get_price_history() |
Daily OHLCV price history |
ibkr_get_trading_schedule() |
Exchange trading schedule |
ibkr_place_order() |
Place a market order |
ibkr_get_orders() |
List open orders |
ibkr_cancel_order() |
Cancel an open order |