> This page is for Web API.

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://ibkrcampus.com/docs/llms.txt.

# Establishing the Websocket with Client Portal Gateway

Next, you will need to build your websocket to wss\://localhost:5000/v1/api/ws. In your request to establish the websocket, be sure to set your cookie header as "api=\{'session' value here}"

#### Python

```python
ws = websocket.WebSocketApp(
  url="wss://localhost:5000/v1/api/ws",
  on_open=on_open,
  on_message=on_message,
  on_error=on_error,
  on_close=on_close,
  cookie=f"api={sessionToken}"
)
ws.run_forever()
```

#### Generic

```generic
curl -i -k -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H --cookie "api=d21b8cf5ebc8ea01c6ce37c8125ec83f" wss://localhost:5000/v1/api/ws
```