---
id: "M:cAlgo.API.WebSocketClient.Close(cAlgo.API.WebSocketClientCloseStatus,System.String)"
kind: "method"
type: "T:cAlgo.API.WebSocketClient"
url: "https://help.ctrader.com/ctrader-algo/references/WebSocket/WebSocketClient/Close/"
---

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

# WebSocketClient.Close

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

## Close(WebSocketClientCloseStatus closeStatus, string closeStatusDescription)

Disconnects WebSocketClient.

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 void Close(WebSocketClientCloseStatus closeStatus, string closeStatusDescription)
```

Python:

```python
webSocketClient.Close(closeStatus: WebSocketClientCloseStatus, closeStatusDescription: str) -> None
```

### Parameters

- `closeStatus` (`WebSocketClientCloseStatus`, Python `WebSocketClientCloseStatus`): Close status / reason.
- `closeStatusDescription` (`string`, Python `str`): Close status / reason description.

### Examples

C#:

```csharp
private WebSocketClient _client;

protected override void OnStart()
{
    _client = new WebSocketClient();
    _client.Connect(new Uri("wss://stream.example.com/quotes"));
}

protected override void OnStop()
{
    _client.Close(WebSocketClientCloseStatus.NormalClosure, "cBot stopped");
}
```

Python:

```python
from System import Uri

def on_start(self):
    self.client = WebSocketClient()
    self.client.Connect(Uri("wss://stream.example.com/quotes"))

def on_stop(self):
    self.client.Close(WebSocketClientCloseStatus.NormalClosure, "cBot stopped")
```

