IBKR Trading APIs

Execute trades through Interactive Brokers using the bearer token authentication. These endpoints support market orders, limit orders, and advanced order types.

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

Note: Multiple records may exist for a single ticker on different exchanges. Filter by valid exchanges to ensure you get the correct contract ID.

Valid Exchanges: NYSE, NASDAQ, ARCA, AMEX, BATS

Example:

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
  });

Overview

IBKR provides three key trading endpoints:

  1. Preview Order - Validate orders before execution
  2. Submit Order - Place actual trading orders
  3. Order Status - Check execution status of placed orders

Preview Order

Validate an order and see potential margin impact before execution.

IBKR Documentation

Endpoint

POST https://api.ibkr.com/v1/api/iserver/account/{accountId}/orders/whatif

Purpose

Simulate an order execution without actually placing it. Returns:

  • Order validation results
  • Margin requirements
  • Commission estimates
  • Price impact analysis

Request

{
  "orders": [
    {
      "conid": 265598,
      "orderType": "MKT",
      "side": "BUY",
      "tif": "DAY",
      "ticker": "AAPL",
      "acctId": "U25076105",
      "cashQty": 1978,
      "outsideRTH": false
    }
  ],
  "outsideRegularHours": false
}

Response

{
  "amount": {
    "amount": "1,977.60 USD (10 Shares)",
    "commission": "1 USD",
    "total": "1,978.60 USD"
  },
  "equity": {
    "current": "123,456",
    "change": "-1",
    "after": "123,455"
  },
  "initial": {
    "current": "1000",
    "change": "652",
    "after": "1652"
  },
  "maintenance": {
    "current": "900",
    "change": "590\"\"",
    "after": "1490"
  },
  "position": {
    "current": "20",
    "change": "10",
    "after": "30"
  },
  "warn": null,
  "error": null
}

Parameters

ParameterTypeRequiredDescription
conidintegerYesContract ID of security
orderTypestringYesMKT (market) or LMT (limit)
sidestringYesBUY or SELL
tifstringYesTime in force: DAY, GTC, etc.
tickerstringYesStock ticker symbol
acctIdstringYesAccount ID
cashQtynumberConditionalAmount in dollars (for BUY orders)
quantitynumberConditionalShare quantity (for SELL or LMT orders)
pricenumberConditionalLimit price (for LMT orders)

Submit Order

Place an actual trading order.

IBKR Documentation

Endpoint

POST https://api.ibkr.com/v1/api/iserver/account/{accountId}/orders

Purpose

Execute a real order on the market. Requires valid session and sufficient margin.

Request

{
  "orders": [
    {
      "conid": 265598,
      "orderType": "MKT",
      "side": "BUY",
      "tif": "DAY",
      "ticker": "AAPL",
      "acctId": "U25076105",
      "cashQty": 1000,
      "outsideRTH": false
    }
  ],
  "outsideRegularHours": false
}

Response

[
  {
    "order_id": "1370093239",
    "order_status": "PreSubmitted",
    "encrypt_message": "1"
  }
]

Important Notes

  • Order must pass validation (use Preview Order first)
  • Session must be authenticated and connected
  • Sufficient margin required
  • Orders execute based on current market conditions

Order Status

Check the execution status and details of a placed order.

IBKR Documentation

Endpoint

GET https://api.ibkr.com/v1/api/iserver/account/order/status/{orderId}

Purpose

Retrieve current status, execution details, and any fills for an order.

Response

{
  "sub_type": null,
  "request_id": "209",
  "server_id": "0",
  "order_id": 1799796559,
  "conidex": "265598",
  "conid": 265598,
  "symbol": "AAPL",
  "side": "S",
  "contract_description_1": "AAPL",
  "listing_exchange": "NASDAQ.NMS",
  "option_acct": "c",
  "company_name": "APPLE INC",
  "size": "0.0",
  "total_size": "5.0",
  "currency": "USD",
  "account": "U1234567",
  "order_type": "MARKET",
  "cum_fill": "5.0",
  "order_status": "Filled",
  "order_ccp_status": "2",
  "order_status_description": "Order Filled",
  "tif": "DAY",
  "fg_color": "#FFFFFF",
  "bg_color": "#000000",
  "order_not_editable": true,
  "editable_fields": "",
  "cannot_cancel_order": true,
  "deactivate_order": false,
  "sec_type": "STK",
  "available_chart_periods": "#R|1",
  "order_description": "Sold 5 Market, Day",
  "order_description_with_contract": "Sold 5 AAPL Market, Day",
  "alert_active": 1,
  "child_order_type": "0",
  "order_clearing_account": "U1234567",
  "size_and_fills": "5",
  "exit_strategy_display_price": "193.12",
  "exit_strategy_chart_description": "Sold 5 @ 192.26",
  "average_price": "192.26",
  "exit_strategy_tool_availability": "1",
  "allowed_duplicate_opposite": true,
  "order_time": "231211180049"
}

Status Values

StatusMeaning
SubmittedOrder accepted but not yet executed
FilledOrder completely filled
Partially FilledOrder partially filled, may fill more
CancelledOrder cancelled
RejectedOrder rejected by exchange

Usage Example

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",
    },
  },
);

Next Steps

Was this page helpful?

PiTrade

PiTrade gives investors in over 190 countries access to the U.S. stock market through real, transparent portfolios you can build yourself or invest in Strategizer Portfolios. As an SEC-registered investment adviser, powered by Interactive Brokers, PiTrade makes investing more transparent and accessible.

This content is provided for informational purposes only and is not intended as and may not be relied on in any manner as investment advice, a recommendation of any interest in any security offered herein. All investments involve risk, including the possible loss of principal. Past performance does not guarantee future results, and investors should consider their own investment goals, risk tolerance, and financial situation before investing. The information contained herein is subject to change.

The platform "PiTrade" is operated by Pioneer Advisory LLC, a subsidiary of Pioneer Investing Inc. which holds ownership rights related hereto.

Advisory services are provided by Pioneer Advisory LLC, an SEC-registered investment adviser.

Brokerage and clearing services are provided by Interactive Brokers LLC, a SEC-registered broker-dealer, member FINRA/SIPC, to retail customers for US-listed, registered securities and ETFs on a self-directed basis.

The registrations and memberships above in no way imply that the SEC, FINRA, or SIPC has endorsed the entities, products or services discussed herein.

Interactive Brokers LLC is a registered Broker-Dealer, Futures Commission Merchant and Forex Dealer Member, regulated by the U.S. Securities and Exchange Commission (SEC), the Commodity Futures Trading Commission (CFTC) and the National Futures Association (NFA), and is a member of the Financial Industry Regulatory Authority (FINRA) and several other self-regulatory organizations. Interactive Brokers does not endorse or recommend any introducing brokers, third-party financial advisors or hedge funds, including Pioneer Advisory LLC. Interactive Brokers provides execution and clearing services to customers. None of the information contained herein constitutes a recommendation, offer, or solicitation of an offer by Interactive Brokers to buy, sell or hold any security, financial product or instrument or to engage in any specific investment strategy. Interactive Brokers makes no representation, and assumes no liability to the accuracy or completeness of the information provided on this website.

For more information regarding Interactive Brokers, please visit www.interactivebrokers.com

© 2026 Pioneer Investing Inc. All Rights Reserved.