---
id: "M:cAlgo.API.WebSocketClient.#ctor"
kind: "constructor"
type: "T:cAlgo.API.WebSocketClient"
url: "https://help.ctrader.com/ctrader-algo/references/WebSocket/WebSocketClient/Constructor/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# WebSocketClient constructor

Member of [WebSocketClient](https://help.ctrader.com/ctrader-algo/references/WebSocket/WebSocketClient/index.md).

## WebSocketClient()

Creates a WebSocketClient with default options.

Environments: Desktop supported · CLI supported · Cloud not supported.

- Cloud: Connect, Send and Close do nothing: "WebSocket is not supported in cloud environment." is written to the log, State stays None and no events are raised.

C#:

```csharp
public WebSocketClient()
```

Python:

```python
WebSocketClient()
```

### Examples

C#:

```csharp
var client = new WebSocketClient();
client.TextReceived += args => Print("Received: {0}", args.Text);
client.Connect(new Uri("wss://stream.example.com/quotes"));
```

Python:

```python
from System import Uri

client = WebSocketClient()
client.TextReceived += lambda args: api.Print(f"Received: {args.Text}")
client.Connect(Uri("wss://stream.example.com/quotes"))
```

## WebSocketClient(WebSocketClientOptions options)

Creates a WebSocketClient with passed options.

Environments: Desktop supported · CLI supported · Cloud not supported.

- Cloud: Connect, Send and Close do nothing: "WebSocket is not supported in cloud environment." is written to the log, State stays None and no events are raised.

C#:

```csharp
public WebSocketClient(WebSocketClientOptions options)
```

Python:

```python
WebSocketClient(options: WebSocketClientOptions)
```

### Parameters

- `options` (`WebSocketClientOptions`, Python `WebSocketClientOptions`):

### Examples

C#:

```csharp
var options = new WebSocketClientOptions { KeepAliveInterval = TimeSpan.FromSeconds(10) };
var client = new WebSocketClient(options);
client.Connect(new Uri("wss://stream.example.com/quotes"));
```

Python:

```python
from System import Uri, TimeSpan

options = WebSocketClientOptions()
options.KeepAliveInterval = TimeSpan.FromSeconds(10)
client = WebSocketClient(options)
client.Connect(Uri("wss://stream.example.com/quotes"))
```

