Establishing the Websocket with OAuth

View as MarkdownOpen in Claude

The process for those authenticating with OAuth is similar, though slightly different. In addition to the API cookie, you must also include the “oauth_token” query param which should be set to the user’s access token value.

1ws = websocket.WebSocketApp(
2 url="wss://api.ibkr.com/v1/api/ws?oauth_token={accessToken}",
3 on_open=on_open,
4 on_message=on_message,
5 on_error=on_error,
6 on_close=on_close,
7 cookie=f"api={sessionToken}"
8)
9ws.run_forever()