Interactive Brokers Trading APIs
Execute trades directly against Interactive Brokers using your bearer token. These endpoints cover previewing an order's margin impact, submitting it, and checking its execution status.
Authentication
All requests require the Interactive Brokers bearer token, obtained from the Bearer Token API:
Authorization: Bearer <BEARER_TOKEN>
Getting Contract IDs (CONID)
Before placing orders, you need the Contract ID (CONID) for each security. IBKR provides a CSV file with contract IDs for fractional share trading.
Download: IBKR Fractional Shares CSV
File Format:
#SYMBOL,MAIN_EXCHANGE,DESCRIPTION,IB_CONTRACT_ID,SCHEDULED_INELIGIBILTY_DATE AAP,NYSE,ADVANCE AUTO PARTS INC,4027, ABM,NYSE,ABM INDUSTRIES INC,4050, ABT,NYSE,ABBOTT LABORATORIES .,4065, ADC,NYSE,AGREE REALTY CORP,4151,
Usage:
1. Download the CSV file 2. Parse it to create a symbol → IB_CONTRACT_ID mapping 3. Use the IB_CONTRACT_ID in your order requests
Multiple records may exist for a single ticker on different exchanges — filter by valid exchanges (NYSE, NASDAQ, ARCA, AMEX, BATS) to ensure you get the correct contract ID.
const fs = require("fs");
const csv = require("csv-parser");
const symbolToConid = {};
const validExchanges = new Set(["NYSE", "NASDAQ", "ARCA", "AMEX", "BATS"]);
fs.createReadStream("fracshare_stk.csv")
.pipe(csv())
.on("data", (row) => {
if (validExchanges.has(row.MAIN_EXCHANGE)) {
symbolToConid[row["#SYMBOL"]] = row.IB_CONTRACT_ID;
}
})
.on("end", () => {
console.log("ABT Contract ID:", symbolToConid["ABT"]); // 4065
});1. Preview Order
POST https://api.ibkr.com/v1/api/iserver/account/{accountId}/orders/whatifSimulate an order execution without placing it. Returns order validation results, margin requirements, commission estimates, and price impact analysis.
Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
| `conid` | integer | Yes | Contract ID of security |
| `orderType` | string | Yes | `MKT` (market) or `LMT` (limit) |
| `side` | string | Yes | `BUY` or `SELL` |
| `tif` | string | Yes | Time in force: `DAY`, `GTC`, etc. |
| `ticker` | string | Yes | Stock ticker symbol |
| `acctId` | string | Yes | Account ID |
| `cashQty` | number | Conditional | Amount in dollars (for BUY orders) |
| `quantity` | number | Conditional | Share quantity (for SELL or LMT orders) |
| `price` | number | Conditional | Limit price (for LMT orders) |
2. Submit Order
POST https://api.ibkr.com/v1/api/iserver/account/{accountId}/ordersExecute a real order on the market. Requires an authenticated, connected session and sufficient margin.
Notes:
- Order must pass validation — use Preview Order first
- Session must be authenticated and connected, see IBKR Session Management
- Orders execute based on current market conditions
3. Order Status
GET https://api.ibkr.com/v1/api/iserver/account/order/status/{orderId}Retrieve the current status, execution details, and any fills for a placed order.
Status Values:
| Status | Meaning |
|---|---|
| `Submitted` | Order accepted but not yet executed |
| `Filled` | Order completely filled |
| `Partially Filled` | Order partially filled, may fill more |
| `Cancelled` | Order cancelled |
| `Rejected` | Order rejected by exchange |
Usage Example
Preview an order, submit it, then poll its status:
const IBKR_BASE_PATH = "https://api.ibkr.com";
// 1. Preview order first
const previewResponse = await fetch(
`${IBKR_BASE_PATH}/v1/api/iserver/account/U25076105/orders/whatif`,
{
method: "POST",
headers: {
Authorization: `Bearer ${bearerToken}`,
"Content-Type": "application/json",
"User-Agent": "Your Application/1.0",
},
body: JSON.stringify({
orders: [
{
conid: 265598,
orderType: "MKT",
side: "BUY",
tif: "DAY",
ticker: "AAPL",
acctId: "U25076105",
cashQty: 1000,
},
],
outsideRegularHours: false,
}),
},
);
// 2. If preview successful, place order
const orderResponse = await fetch(
`${IBKR_BASE_PATH}/v1/api/iserver/account/U25076105/orders`,
{
method: "POST",
headers: {
Authorization: `Bearer ${bearerToken}`,
"Content-Type": "application/json",
"User-Agent": "Your Application/1.0",
},
body: JSON.stringify({
orders: [
{
conid: 265598,
orderType: "MKT",
side: "BUY",
tif: "DAY",
ticker: "AAPL",
acctId: "U25076105",
cashQty: 1000,
},
],
outsideRegularHours: false,
}),
},
);
const { order_id } = await orderResponse.json();
// 3. Check order status
const statusResponse = await fetch(
`${IBKR_BASE_PATH}/v1/api/iserver/account/order/status/${order_id}`,
{
headers: {
Authorization: `Bearer ${bearerToken}`,
"User-Agent": "Your Application/1.0",
},
},
);For a full working script that also handles authentication and session setup, see the Complete Flow Example.