> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bayse.markets/llms.txt
> Use this file to discover all available pages before exploring further.

# Errors & rate limits

> Error handling and rate limits for WebSocket connections

## Error format

When the server encounters an error processing a message, it sends an error event:

```json theme={null}
{
  "type": "error",
  "data": {
    "message": "Event ID is required"
  },
  "timestamp": 1700000000000
}
```

The `data.message` field contains a human-readable description of the error.

## Common errors

### Invalid message format

Sent when the message is not valid JSON.

```json theme={null}
{
  "type": "error",
  "data": { "message": "Invalid message format" },
  "timestamp": 1700000000000
}
```

### Missing required fields

Sent when a required field is missing from the message.

```json theme={null}
{
  "type": "error",
  "data": { "message": "Event ID is required" },
  "timestamp": 1700000000000
}
```

Other examples:

* "Symbols required to subscribe to asset prices"
* "Room name is required"

### Unknown message type

Sent when the `type` field does not match any known message type.

```json theme={null}
{
  "type": "error",
  "data": { "message": "unknown message type: INVALID_TYPE" },
  "timestamp": 1700000000000
}
```

### Unsupported values

Sent when a field value is not supported.

```json theme={null}
{
  "type": "error",
  "data": { "message": "Unsupported currency. Supported currencies are USD and NGN" },
  "timestamp": 1700000000000
}
```

```json theme={null}
{
  "type": "error",
  "data": { "message": "Unsupported symbol: DOGEUSDT. Supported symbols are BTCUSDT, ETHUSDT, SOLUSDT, XAUUSD, EURUSD, GBPUSD, USDNGN" },
  "timestamp": 1700000000000
}
```

### Wrong endpoint

Sent when you try to subscribe to a channel on the wrong endpoint.

```json theme={null}
{
  "type": "error",
  "data": { "message": "channel \"asset_prices\" is not available on /ws/v1/markets; use /ws/v1/realtime instead" },
  "timestamp": 1700000000000
}
```

### Rate limit exceeded

Sent when the client sends too many messages.

```json theme={null}
{
  "type": "error",
  "data": { "message": "rate limit exceeded: too many messages" },
  "timestamp": 1700000000000
}
```

## Rate limits

| Limit        | Value              | Scope          |
| ------------ | ------------------ | -------------- |
| Message rate | 10 messages/second | Per connection |

WebSocket upgrades are rate-limited per IP.

When the message rate is exceeded, the server sends a rate limit error but keeps the connection open. Slow down your message rate to resume normal operation.

## Best practices

* **Always handle `error` events.** Check `msg.type === "error"` and log the message for debugging.
* **Don't retry immediately on errors.** If you receive a rate limit error, slow down before sending more messages.
* **Use the right endpoint.** Each endpoint only accepts specific channels. See the error message for which endpoint to use.
* **Validate before sending.** Check that required fields like `eventId`, `marketIds`, and `symbols` are present before sending to avoid unnecessary round-trips.
