Interactive Brokers Session Management
Interactive Brokers sessions have timeouts and require active maintenance. These endpoints initialize, validate, refresh, and manage session state so your integration stays connected.
Authentication
All requests require the Interactive Brokers bearer token, obtained from the Bearer Token API:
Authorization: Bearer <BEARER_TOKEN>
1. Initialize Session
POST https://api.ibkr.com/v1/api/iserver/auth/ssodh/init
Start a new session to establish connection and receive session tokens.
2. Validate Session
GET https://api.ibkr.com/v1/api/sso/validate
Confirm session validity before executing trades.
Status Codes: 200 session is valid, 401 session expired or invalid.
3. Authentication Status
GET https://api.ibkr.com/v1/api/iserver/auth/status
Check if you're authenticated, connected, and competitive (no other sessions).
Response Fields:
| Field | Meaning |
|---|---|
| `authenticated` | User is authenticated |
| `connected` | API connection established |
| `competing` | Another session exists (conflicts) |
4. Tickle (Keep-Alive)
GET https://api.ibkr.com/v1/api/tickle
Send a keep-alive signal to maintain the session.
Keep-Alive Interval: Call every 60 seconds to maintain an active session. If no tickle is received for an extended period, the session times out.
5. Suppress Messages
POST https://api.ibkr.com/v1/api/iserver/questions/suppress
Suppress IBKR confirmation dialogs for specific order types, to avoid confirmation prompts during programmatic trading.
Common Message IDs:
| ID | Description |
|---|---|
| `o163` | Order confirmation dialogs |
| `o354` | Risk management warnings |
| `o382` | Commission warnings |
| `p6` | General confirmations |
Session Maintenance Flow
1. Get Bearer Token
└─> /user/bearer-token
2. Initialize Session
└─> POST /v1/api/iserver/auth/ssodh/init
3. Verify Connected
└─> GET /v1/api/iserver/auth/status
4. Suppress Messages
└─> POST /v1/api/iserver/questions/suppress
5. Keep Alive (every 60 seconds)
└─> GET /v1/api/tickle
6. Before Trading
└─> GET /v1/api/sso/validate
└─> GET /v1/api/iserver/auth/status
7. Place Orders / Check Status
└─> POST /v1/api/iserver/account/{acctId}/orders/whatif
└─> POST /v1/api/iserver/account/{acctId}/orders
└─> GET /v1/api/iserver/account/order/status/{orderId}Usage Example
A SessionManager that initializes the session, keeps it alive on an interval, and exposes validation helpers:
const IBKR_BASE_PATH = "https://api.ibkr.com";
class SessionManager {
constructor(bearerToken) {
this.bearerToken = bearerToken;
this.sessionId = null;
this.keepAliveInterval = null;
}
async initializeSession() {
const response = await fetch(
`${IBKR_BASE_PATH}/v1/api/iserver/auth/ssodh/init`,
{
method: "POST",
headers: {
Authorization: `Bearer ${this.bearerToken}`,
"Content-Type": "application/json",
"User-Agent": "Your Application/1.0",
},
body: JSON.stringify({
publish: true,
compete: true,
}),
},
);
const data = await response.json();
this.sessionId = data.sessionId;
return data;
}
async validateSession() {
const response = await fetch(`${IBKR_BASE_PATH}/v1/api/sso/validate`, {
headers: {
Authorization: `Bearer ${this.bearerToken}`,
"User-Agent": "Your Application/1.0",
},
});
return response.status === 200;
}
async tickleSession() {
await fetch(`${IBKR_BASE_PATH}/v1/api/tickle`, {
headers: {
Authorization: `Bearer ${this.bearerToken}`,
"User-Agent": "Your Application/1.0",
},
});
}
startKeepAlive() {
this.keepAliveInterval = setInterval(
() => this.tickleSession(),
60 * 1000, // Every 60 seconds
);
}
stopKeepAlive() {
if (this.keepAliveInterval) {
clearInterval(this.keepAliveInterval);
}
}
}For a full working script that also handles authentication and trading, see the Complete Flow Example.
Best Practices
1. Validate Before Trading - Always check validateSession() before placing orders
2. Keep Alive - Call tickle every 60 seconds to prevent session timeout
3. Monitor Status - Regularly check auth status for competing sessions
4. Suppress Early - Suppress messages during session initialization
5. Handle Errors - Implement retry logic for failed session calls
6. Session Cleanup - Stop the keep-alive timer when done
Troubleshooting
| Issue | Solution |
|---|---|
| Session expired | Request a new bearer token and reinitialize |
| Competing session | Another login exists; stop the other session |
| Validation fails | Tickle the session and retry |
| Messages not suppressed | Ensure message IDs are correct |