Third-Party Web API v1
/oauth
OAuth example client (java)
- OAuth RFC
- Interactive brokers onboarding instructions. Includes a fully worked example; private keys for the example are below.
Obtain a request token. See section 6.1 of the OAuth v1.0a
specification for more information.
Note: We do not return an oauth_token_secret in the
response as we are using RSA signatures rather than PLAINTEXT authentication.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "object", "properties": { "oauth_token": { "type" : "string" } } } |
Unsuccessful Response | |
Return codes | 400, 401, 403, 408 |
Obtain an access token using the request token and the verification code you received after the user provided authorization. See section 6.3 of the OAuth v1.0a specification for more details.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "object", "properties": { "oauth_token": { "type" : "string" }, "oauth_token_secret": { "type" : "string" } } } |
Unsuccessful Response | |
Return codes | 400, 401, 403, 408 |
In order to access protected IB resources, a live session token is required. This endpoint allows consumers to
obtain a live session token to access these resources using an OAuth access token and the Diffie-Hellman prime and
generator supplied during the registration process.
Note: This is an additional
IB-specific step, and not part of the OAuth v1.0a specification. Please refer to the "OAuth
at Interactive Brokers" document for more details.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "object", "properties": { "diffie_hellman_response": { "type" : "string" }, "live_session_token_signature": { "type" : "string" } } } |
Unsuccessful Response | |
Return codes | 400, 401, 403, 408 |
/accounts
Accounts that are authorized before 16:55 EST will be accessible via the API the following day (after the 'nightly
refresh').
After the initial authorization by a given user and before the nightly refresh has occurred,
all /accounts/ endpoints for that user will return HTTP status code 204 (204 is 'no content') .
Upon
subsequent account authorizations, only previously authorized accounts will appear in /accounts before the nightly
refresh.
Resources with the HTTP method tagged with '*' may return HTTP 423 (Resource Locked) when queried repeatedly.
Allows the caller to request a list of accounts associated with the session.
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "object", "properties" : { "accounts" : { "type" : "array" }, "items" : { "type" : "string" } } } |
Unsuccessful Response | |
Return codes | 202, 204, 401, 403, 408 |
Returns a list of positions held by the account passed in the URL.
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "Position": { "type": "number" }, "AverageCost": { "type": "number" }, "ContractId": { "type": "number" } } } } |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408 |
Returns a list of account and margin balances associated with the account passed in the URL.
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Example | see summary.json |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408 |
Returns a list of orders for the account passed in the URL.
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "CustomerOrderId": { "type": "number" }, "ContractId": { "type": "number" }, "Ticker": { "type": "string" }, "ListingExchange": { "type": "string" }, "RemainingQuantity": { "type": "number" }, "FilledQuantity": { "type": "number" }, "OrderType": { "type": "FIXOrderType"}, "TimeInForce": { "type" : "FIXTIF" }, "OutsideRTH": { "type" : "string" }, "Side": { "type": "string", "type": "FIXSide"}, "Price": { "type": "number"}, "Status": {"type": "Order Status"}, "Warning": {"type": "string"}, "TransactionTime": { "type": "string"} } } } |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408 |
To specify the contract, you provide a value for the ContractId field, OR Ticker/ListingExchange/InstrumentType=STK for stocks OR Ticker/Currency/InstrumentType=CASH for FX.
Required Fields For Security Resolution
Asset Class | Instrument Type | Required Fields | Example |
---|---|---|---|
Stocks | STK |
|
|
FX | CASH |
|
|
Transmits an order tagged with the specified CustomerOrderId for the account passed in the URL.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "CustomerOrderId": { "type": "number" }, "ContractId": { "type": "number" }, "Ticker": { "type": "string" }, "ListingExchange": { "type": "string" }, "RemainingQuantity": { "type": "number" }, "FilledQuantity": { "type": "number" }, "OrderType": { "type": "FIXOrderType"}, "TimeInForce": { "type" : "FIXTIF" }, "OutsideRTH": { "type" : "string" }, "Side": { "type": "string", "type": "FIXSide"}, "Price": { "type": "number"}, "Status": {"type": "Order Status"}, "Warning": {"type": "string"}, "TransactionTime": { "type": "string"} } } } |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408, 423 |
Returns the order with the referenced Customer Order ID for the account passed in the URL.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "CustomerOrderId": { "type": "number" }, "ContractId": { "type": "number" }, "Ticker": { "type": "string" }, "ListingExchange": { "type": "string" }, "RemainingQuantity": { "type": "number" }, "FilledQuantity": { "type": "number" }, "OrderType": { "type": "FIXOrderType" }, "TimeInForce": { "type" : "FIXTIF" }, "OutsideRTH": { "type" : "string" }, "Side": { "type": "string", "type": "FIXSide"}, "Price": { "type": "number"}, "Status": {"type": "Order Status"}, "Warning": {"type": "string"}, "TransactionTime": { "type": "string"} } } } |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408 |
Cancels the order with the referenced Customer Order ID for the account passed in the URL.
Parameters
Parameter | Value | Description |
---|---|---|
CustomerOrderId | The order ID assigned by the customer. |
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "CustomerOrderId": {"type" : "string" }, "Symbol": {"type" : "string" }, "OrderQty": {"type" : "number" }, "Price": {"type" : "number" }, "Side": { "type": "string", "type": "FIXSide"}, "Status": {"type": "Order Status"}, "Warning": {"type": "string"}, "OrderType": { "type": "FIXOrderType" } } } } |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408, 423 |
Allows the caller to modify the order with the referenced Customer Order ID specified in the URL. A separate Customer Order ID must be provided in the request body for the modification.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "OrigCustomerOrderId": {"type" : "string" }, "CustomerOrderId": {"type" : "string" }, "OrderQty": {"type" : "number" }, "Price": {"type" : "number" }, "Side": { "type": "string", "type": "FIXSide"}, "Status": {"type": "Order Status"}, "Warning": {"type": "string"}, "OrderType": { "type": "FIXOrderType" } } } } |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408, 423 |
This endpoint allows the consumer to check the impact that an order would have on the account, including margin, NLV and estimated commission costs.
To specify the contract, you provide a value for the ContractId field, OR Ticker/ListingExchange/InstrumentType=STK for stocks OR Ticker/Currency/InstrumentType=CASH for FX.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "object", "properties": { "EquityWithLoan": { "type": "number" }, "InitMargin": { "type": "number" }, "InitMarginBefore": { "type": "number" }, "MaintMargin": { "type": "number" }, "MaintMarginBefore": { "type": "number" }, "MarginCurrency": { "type": "string" }, "Commission": { "type": "number" }, "MinCommissions": { "type": "number" }, "MaxCommissions": { "type": "number" }, "CommissionsCurrency": { "type": "string" } } } |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408 |
Returns a list of trades for the account starting at the given 'since' date to the current time (now()).
Timezone is UTC.
Any request with a future since date or going further than one week will result in an HTTP 400 bad
request response. Calling /trades without since will return all trades for the past 24 hours.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "CustomerOrderId": { "type": "number" }, "ContractId": { "type": "number" }, "OrderId": { "type": "string" }, "Ticker": { "type": "string" }, "ListingExchange": { "type": "string" }, "Currency": { "type": "string" }, "Side": { "type": "string", "type": "FIXSide"}, "OrderType": { "type": "string", "type": "FIXOrderType"}, "FilledQuantity": { "type": "number" }, "RemainingQuantity": { "type": "number" }, "Quantity": { "type": "number" }, "TradePrice": { "type": "number"}, "TradeSize": { "type": "number"}, "AvgPrice": { "type": "number"}, "ExecutionTime": { "type": "string"}, "ExecId": { "type": "string"}, "Commission": { "type": "number"}, "CommissionCurrency": { "type": "string"} "LastMarket": { "type": "string"} } } } |
Unsuccessful Response | |
Return codes | 202, 204, 400, 401, 403, 408 |
/secdef
Allows the consumer to request details regarding a trading product from the IB trading product database.
Parameters
or orResponses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "object", "properties": { "ContractId": { "type": "number" }, "Ticker": {"type": "string" }, "SecurityType": {"type": "string" }, "Exchange": { "type": "string" }, "CompanyName": { "type": "string" }, "Currency": { "type": "string" } } } |
Unsuccessful Response | |
Return codes | 202, 400, 401, 403, 408 |
/marketdata
This endpoint allows the consumer to request a market data snapshot for one or more trading products. Consumers need to provide unique identifiers (conids) for the products in the IB product database (retrievable using the /secdef endpoint).
The 'market' values are integers whose bits indicate the exchange(s) making up the quote. The mapping of bit to exchange is obtained from the marketdata/exchange_component endpoint.
For example, if a bid has a 'market' value of 5 and the exchange_component result has the map
0 => NYSE 1 => ISLAND 2 => ARCAthen the exchanges contributing to the bid size are NYSE and ARCA. Similarly, if market=2, then only ISLAND is contributing.
Parameters
or orResponses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "Conid": {"type": "number"}, "Temporality" : { "type" : "number" }, "Complete" : { "type" : "boolean" }, "Trade": { "type": "object", "properties" : { "market" : {"type" : "number"}, "price" : {"type" : "number"}, "size" : {"type" : "number"}, "time" : {"type" : "number"} } }, "Closing": { "type": "object", "properties" : { "price" : {"type" : "number"}, } }, "Bid": { "type": "object", "properties" : { "market" : {"type" : "number"}, "price" : {"type" : "number"}, "size" : {"type" : "number"} } }, "Offer": { "type": "object", "properties" : { "market" : {"type" : "number"}, "price" : {"type" : "number"}, "size" : {"type" : "number"} } } } } } |
Unsuccessful Response | |
Return codes | 400, 401, 403, 408 |
This endpoint provides a bit mapping for the bid/ask/last 'market' values in the snapshot response.
Parameters
Responses
Successful Response | |
---|---|
Return code | 200 OK |
Schema | { "type": "array", "items": { "type": "object", "properties": { "Conid": {"type": "number"}, "Complete": { "type": "boolean" }, "mapping": { "type": "array", "items": { "type": "object", "properties": { "bit": {"type": "number"}, "code": {"type": "string"}, "exchange": {"type": "string"} } } } } } } |
Unsuccessful Response | |
Return codes | 400, 401, 403, 408 |
Models
Order Status
InvalidOrderStatus = -1 New = '0' PartiallyFilled = '1' Filled = '2' DoneForTheDay = '3' Canceled = '4' Replaced = '5' PendingCancelReplace = '6' Stopped = '7' Rejected = '8' Suspended = '9' PendingNew = 'A' Calculated = 'B' Expired = 'C' AcceptedForBidding = 'D' PendingReplace = 'E'
FIX Order Type
Market = '1' Limit = '2' Stop = '3' StopLimit = '4'
FIX Side
Buy = '1' Sell = '2'
FIX TIF (Time In Force) Model
Day = '0' GTC (Good till Cancel) = '1' IOC (Immediate or Cancel) = '3' Open = '2' Close = '7'
Execution Type
Invalid = -1 New = '0' PartialFill = '1' Fill = '2' DoneForDay = '3' ETCanceled = '4' Replace = '5' PendingCancel = '6' Stopped = '7' Rejected = '8' Suspended = '9' PendingNew = 'A' Calculated = 'B' Expired ='C' Restated = 'D' PendingReplace = 'E' Trade = 'F' TradeCorrect = 'G' TradeCancel = 'H' OrderStatus = 'I
Exchanges
US American Stock Exchange = AMEX Bulletin Board = ARCAEDGE New York Stock Exchange = NYSE NASDAQ = ISLAND Pink Sheets = ARCAEDGE OTCQB = ARCAEDGE OTCQX = ARCAEDGE Canada Toronto Exchange = TSE Venture Exchange = VENTURE NEX = AEQNEO
OrderRestrictions
'1' Program Trade '2' Index Arbitrage '3' Non-Index Arbitrage
Temporality
0 = Real time data 1 = Delayed data