# Trades

View and manage trades.

## Endpoints

| Method | Path                    | Description         |
| ------ | ----------------------- | ------------------- |
| GET    | `/v1/trades`            | List trades         |
| GET    | `/v1/trades/:id`        | Get trade           |
| GET    | `/v1/trades/analytics`  | Get trade analytics |
| POST   | `/v1/trades`            | Create trade        |
| POST   | `/v1/trades/:id/cancel` | Cancel trade        |

***

### List Trades

```
GET /v1/trades
```

**Query Parameters:**

| Parameter             | Type    | Description                                                    |
| --------------------- | ------- | -------------------------------------------------------------- |
| `strategy_id`         | string  | Filter by strategy                                             |
| `exchange_account_id` | string  | Filter by exchange account                                     |
| `status`              | string  | `PENDING`, `FILLED`, `PARTIALLY_FILLED`, `CANCELLED`, `FAILED` |
| `side`                | string  | `BUY` or `SELL`                                                |
| `limit`               | integer | Max results (default 50, max 100)                              |
| `offset`              | integer | Pagination offset                                              |

```bash
curl "https://rest-api.tokenbot.com/v1/trades?status=FILLED&limit=10" \
  -H "X-API-Key: tb_live_your_key"
```

***

### Get Trade

```
GET /v1/trades/:id
```

***

### Get Trade Analytics

```
GET /v1/trades/analytics
```

Returns aggregated trade performance metrics.

```bash
curl https://rest-api.tokenbot.com/v1/trades/analytics \
  -H "X-API-Key: tb_live_your_key"
```

***

### Create Trade

```
POST /v1/trades
```

**Request Body:**

```json
{
  "exchange_account_id": "exc_abc123",
  "trade_pair_id": "tp_btcusdt",
  "type": "LIMIT",
  "side": "BUY",
  "price": 50000.00,
  "amount": 0.1
}
```

***

### Cancel Trade

```
POST /v1/trades/:id/cancel
```

```bash
curl -X POST https://rest-api.tokenbot.com/v1/trades/trd_abc123/cancel \
  -H "X-API-Key: tb_live_your_key"
```
