# Exchanges

Manage connected exchange accounts.

## Endpoints

| Method | Path                     | Description               |
| ------ | ------------------------ | ------------------------- |
| GET    | `/v1/exchanges`          | List exchange accounts    |
| GET    | `/v1/exchanges/:id`      | Get exchange account      |
| POST   | `/v1/exchanges`          | Add exchange account      |
| DELETE | `/v1/exchanges/:id`      | Remove exchange account   |
| POST   | `/v1/exchanges/test`     | Test exchange credentials |
| POST   | `/v1/exchanges/:id/sync` | Sync exchange balance     |

***

### List Exchange Accounts

```
GET /v1/exchanges
```

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

**Response:**

```json
{
  "success": true,
  "data": [
    {
      "id": "exc_abc123",
      "exchange_name": "binance",
      "account_name": "Main Binance",
      "trading_type": "spot",
      "is_active": true,
      "balance": { "BTC": 1.5, "USDT": 10000 },
      "last_sync_at": "2026-02-20T12:00:00Z",
      "created_at": "2026-01-15T10:30:00Z"
    }
  ]
}
```

***

### Get Exchange Account

```
GET /v1/exchanges/:id
```

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

***

### Add Exchange Account

```
POST /v1/exchanges
```

**Request Body:**

```json
{
  "exchange_name": "binance",
  "account_name": "My Binance",
  "trading_type": "spot",
  "api_key": "your_exchange_api_key",
  "api_secret": "your_exchange_api_secret",
  "passphrase": "optional_passphrase"
}
```

```bash
curl -X POST https://rest-api.tokenbot.com/v1/exchanges \
  -H "X-API-Key: tb_live_your_key" \
  -H "Content-Type: application/json" \
  -d '{"exchange_name":"binance","account_name":"My Binance","trading_type":"spot","api_key":"...","api_secret":"..."}'
```

***

### Remove Exchange Account

```
DELETE /v1/exchanges/:id
```

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

***

### Test Exchange Credentials

```
POST /v1/exchanges/test
```

Test exchange API credentials before saving.

**Request Body:**

```json
{
  "exchange_name": "binance",
  "api_key": "your_exchange_api_key",
  "api_secret": "your_exchange_api_secret",
  "trading_type": "spot"
}
```

***

### Sync Exchange Balance

```
POST /v1/exchanges/:id/sync
```

Force a balance sync with the exchange.

```bash
curl -X POST https://rest-api.tokenbot.com/v1/exchanges/exc_abc123/sync \
  -H "X-API-Key: tb_live_your_key"
```
