# Message Format

Our WebSocket API uses JSON-formatted messages for all communication.

### Request Format

All requests follow a consistent structure:

```json
{
  "id": "1",
  "method": "METHOD_NAME",
  "params": {...}
}
```

| Field    | Type              | Required | Description                                    |
|----------|-------------------|----------|------------------------------------------------|
| `id`     | string \| number  | Yes      | Unique identifier for matching request/response |
| `method` | string            | Yes      | The method to invoke                           |
| `params` | object \| array   | No       | Method parameters (varies by method)           |

### Response Format

Successful responses include the request ID and result:

```json
{
  "id": "1",
  "status": 200,
  "result": {...}
}
```

| Field    | Type             | Description                              |
|----------|------------------|------------------------------------------|
| `id`     | string \| number | Matches the request ID                   |
| `status` | number           | HTTP status code |
| `result` | any              | Method-specific response data            |

### Error Response

Error responses include error details:

```json
{
  "id": "1",
  "status": 401,
  "error": {
    "code": -1002,
    "msg": "Authentication required"
  }
}
```

| Field           | Type             | Description                     |
|-----------------|------------------|---------------------------------|
| `id`            | string \| number | Matches the request ID          |
| `status`        | number           | HTTP status code           |
| `error.code`    | number           | Internal error code     |
| `error.msg` | string           | Human-readable error message |

### Error Codes

| Code   | HTTP Status | Description                   |
|--------|-------------|-------------------------------|
| -1000  | 500         | Internal server error         |
| -1002  | 401         | Authentication required       |
| -1003  | 429         | Rate limit exceeded           |
| -1013  | 400         | Invalid parameters            |
| -1020  | 400         | Unsupported operation         |
| -2010  | 400         | Order rejected                |
