# Authentication

You must authenticate yourself when subscribing to any of the sFOX WebSocket feeds.

{% hint style="info" %}
All WebSocket feeds require authentication.
{% endhint %}

Authentication commands should be JSON with the following properties:

<table><thead><tr><th width="129">Property</th><th width="100">Type</th><th>Command</th></tr></thead><tbody><tr><td><strong><code>type</code></strong></td><td>string</td><td><code>"authenticate"</code></td></tr><tr><td><strong><code>apiKey</code></strong></td><td>string</td><td><code>"&#x3C;YOUR-API-KEY>"</code></td></tr></tbody></table>

### Authentication Message

To authenticate yourself to the WebSocket API, you must send an `authenticate` message to the server with an API key for your account. This message is mandatory as all WebSocket feeds require authentication.

#### Authenticate Message

```json
// Request -> Authenticate
{
    "type": "authenticate", 
    "apiKey": "<REPLACE WITH YOUR API KEY>"
}
```

Once a `authenticate` message is received the server responds with an `authenticate` message that specifies whether authentication succeeded or failed.

```json
// Response -> Authenticate
{
    "type": "success",
    "sequence": 1,
    "timestamp": 1727391983733911769,
    "payload": {
        "action": "authenticate"
    },
    "action": "authenticate"
}
```

### Example Code

{% tabs %}
{% tab title="NodeJS" %}

```javascript
const authMessage = {
   type: 'authenticate',
   apiKey: '<API_KEY>',
}
ws.send(JSON.stringify(authMessage))
```

{% endtab %}

{% tab title="Python" %}

```python
auth_message={
  "type": "authenticate",
  "apiKey": "<API KEY>"
}

await ws.send(json_dump(auth_message))
```

{% endtab %}
{% endtabs %}
