Broker API HubMenu

Interactive Brokers API POST /iserver/account/{accountId}/orders

POST/iserver/account/{accountId}/ordersversion v1Orders

Submits an order ticket, a bracket or an OCA group. The reply is either the order ID or a question you must confirm with POST /iserver/reply/{replyId}.

Risk warning: CFDs and spread bets are complex instruments and come with a high risk of losing money rapidly due to leverage. You can lose money on these products, and each provider publishes its own loss figure under FCA rules. You should consider whether you understand how they work and whether you can afford to take the high risk of losing your money. Automated and API trading can amplify losses through bugs, connectivity failures and runaway orders.

Independent and unofficialinteractivebrokers.comchecked

The 200 body is one of four shapes: a list with order_id, order_status and encrypt_message; a list of reply messages with id, message, isSuppressed and messageIds; an object with error; or an advanced order reject. The order ticket fields are listed on IBKR's Modify Open Order reference page and used in IBKR's Placing Orders lesson; the Submit New Order page itself shows the orders array without expanding it.

Parameters

NameInTypeDescription
accountIdrequiredpathstringYour IBKR account ID. The code reads it from the IBKR_ACCOUNT_ID environment variable. Never type it into this site.
ordersbodyarrayArray of order ticket objects. IBKR: only one order ticket may be submitted per request, unless constructing a bracket.
orders[].conidrequiredbodyintegerIB contract ID of the instrument. Find it with GET /iserver/secdef/search.
orders[].orderTyperequiredbodystringIB order type identifier. IBKR's Placing Orders lesson uses STP in its example.
orders[].siderequiredbodystringBUY or SELL.
orders[].tifrequiredbodystringTime in force, such as DAY.
orders[].quantityrequiredbodynumberOrder quantity.
orders[].pricebodynumberOrder price. For the STP example it is the stop price.
orders[].cOIDbodystringYour own client order ID, 64 characters at most.

Authentication headers

NameTypeDescription
AuthorizationstringOAuth only; the Gateway sends none. On the OAuth host this is the SSO bearer token IBKR's reference lists for this call. With the Client Portal Gateway on your own computer the browser login holds the session. Placeholder only.

Request

Written from the method, path and parameters recorded on this page. No demo host is recorded as a plain address for this API, so the samples read the base address from an environment variable. Not executed against a live or demo account. Credentials are read from environment variables on your own machine and are never entered on this site. The request builder writes these same snippets, from the same record.

This call takes a request body. The samples send it as JSON with a Content-Type of application/json (in Python, passing json= sets that header) and a placeholder for each of the 5 body fields the record marks as required. Each placeholder has to be replaced with a real value before the request can succeed.

Python
# Set IBKR_BASE_URL, IBKR_ACCOUNT_ID as environment variables first. Never paste real values into code.
# No demo host is recorded as a plain address for this API, so the base address is read from IBKR_BASE_URL.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: headers Authorization; body fields orders[].price, orders[].cOID.
import os
import requests

BASE_URL = os.environ["IBKR_BASE_URL"]
headers = {}
body = {"orders": [{"conid": 0, "orderType": "...", "side": "...", "tif": "...", "quantity": 0}]}
resp = requests.post(BASE_URL + "/iserver/account/" + os.environ["IBKR_ACCOUNT_ID"] + "/orders", headers=headers, json=body, timeout=10)
resp.raise_for_status()
print(resp.json())
JavaScript
// Set IBKR_BASE_URL, IBKR_ACCOUNT_ID as environment variables first. Never paste real values into code.
// No demo host is recorded as a plain address for this API, so the base address is read from IBKR_BASE_URL.
// Replace each {placeholder}, "..." and 0 with a real value before running.
// Optional and not shown: headers Authorization; body fields orders[].price, orders[].cOID.
// Run as a module, for example a .mjs file, on a Node version that has fetch built in.
const BASE_URL = process.env.IBKR_BASE_URL;
const res = await fetch(BASE_URL + "/iserver/account/" + process.env.IBKR_ACCOUNT_ID + "/orders", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"orders": [{"conid": 0, "orderType": "...", "side": "...", "tif": "...", "quantity": 0}]}),
});
if (!res.ok) throw new Error(`HTTP ${res.status}`);
console.log(await res.json());
curl
# Set IBKR_BASE_URL, IBKR_ACCOUNT_ID as environment variables first. Never paste real values into code.
# No demo host is recorded as a plain address for this API, so the base address is read from IBKR_BASE_URL.
# Replace each {placeholder}, "..." and 0 with a real value before running.
# Optional and not shown: headers Authorization; body fields orders[].price, orders[].cOID.
curl -X POST "$IBKR_BASE_URL/iserver/account/$IBKR_ACCOUNT_ID/orders" \
  -H "Content-Type: application/json" \
  -d '{"orders": [{"conid": 0, "orderType": "...", "side": "...", "tif": "...", "quantity": 0}]}'

Response

A mock response. The values are invented, so check field names against the official reference.

[
  {
    "_mock": true,
    "order_id": "MOCK-ORDER-0001",
    "order_status": "Submitted",
    "encrypt_message": "1"
  }
]

Limits that apply at Interactive Brokers

LimitValueScopeSource
Global requests a second (Web API)10Per authenticated username, that is per Web API sessionibkrcampus.comchecked corroborated by interactivebrokers.com/docs/web-api/trading/usage-and-availability/pacing-limitations
Historical market data requestsEither 10 req/s or 50 req/minute, as the page words itGET /iserver/marketdata/history onlyinteractivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/
Market data snapshot requests a second10GET /iserver/marketdata/snapshot onlyinteractivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/
Order and trade list requests1 req/5 sGET /iserver/orders and GET /iserver/trades, each counted on its owninteractivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/
Session validation requests a minute1GET /sso/validate onlyinteractivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/
Session keep alive requests a second1GET /tickle onlyinteractivebrokers.comchecked corroborated by ibkrcampus.com/campus/ibkr-api-page/webapi-doc/

Interactive Brokers API errors you may meet

All Interactive Brokers API error codes, including 505 more not listed here.