# Currencies (SBX-FX)

TCMB indicative TRY rates since 2005 (forex and banknote, buying and selling) and ECB euro reference rates since 1999, with conversion and history.

Version: v1.0

## Authentication

Send your API key on every request, either as a Bearer token or as the `apikey` query parameter:

```
Authorization: Bearer <YOUR_API_KEY>
https://api.servicebox.io/v1/fx/...?apikey=<YOUR_API_KEY>
```

Get a key: sign up at https://servicebox.io/en/signup and create one on the dashboard. An agent can sign up itself with `POST https://api.servicebox.io/v1/accounts` and `{"email": "...", "apis": ["fx"]}`: the owner of the mailbox approves by email and the agent collects a short-lived key by polling the returned `poll_url`.

## Base URL

`https://api.servicebox.io`

## Endpoints

### GET /v1/fx/conversions

**Convert an amount**

`amount` of `from` in `to` at the official rate on `date` (default: latest). TCMB is used when it publishes both currencies (TRY included), else ECB (EUR included). With TCMB, `rateType` picks the rate each currency is valued at in TRY: `mid` (default, the forex buying/selling midpoint), `buying` or `selling`.

**Credits:** 1 per call

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `from` | query | string | yes | ISO 4217 code. |
| `to` | query | string | yes | ISO 4217 code. |
| `amount` | query | number | no | Default 1. |
| `date` | query | string | no | YYYY-MM-DD. Default: the latest bulletin. |
| `source` | query | string (`tcmb`, `ecb`) | no | Force `tcmb` or `ecb`. |
| `rateType` | query | string (`mid`, `buying`, `selling`) | no | TCMB only: `mid`, `buying` or `selling`. |

**Example**

```bash
curl "https://api.servicebox.io/v1/fx/conversions?from=<from>&to=<to>" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

### GET /v1/fx/currencies

**List currencies**

Every currency TCMB or ECB publishes, with the first and latest date each has. Free.

**Credits:** free (0 credits per call)

No parameters.

**Example**

```bash
curl "https://api.servicebox.io/v1/fx/currencies" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

### GET /v1/fx/rates

**Rates on a date**

Every currency's official rate on `date` (default: the latest bulletin). TCMB: the indicative forex and banknote buying/selling rates in TRY, published at 15:30 Istanbul time on business days. ECB: the euro reference rates, published around 16:00 CET. A date without a bulletin (weekend, holiday) answers the latest one before it; `meta.date` says which.

**Credits:** 1 per call

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `source` | query | string (`tcmb`, `ecb`) | no | `tcmb` (default: Turkish central bank, TRY rates since 2005) or `ecb` (European Central Bank, EUR rates since 1999). |
| `date` | query | string | no | YYYY-MM-DD. Default: the latest bulletin. |
| `currencies` | query | string | no | Comma-separated ISO 4217 codes to include, e.g. USD,EUR. |

**Example**

```bash
curl "https://api.servicebox.io/v1/fx/rates" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

### GET /v1/fx/rates/{code}

**One currency over time**

One currency's rate on every bulletin between `start` and `end` (default: the last 30 days; at most 366 days).

**Credits:** 1 per call

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `code` | path | string | yes | ISO 4217 code, e.g. USD. |
| `source` | query | string (`tcmb`, `ecb`) | no | `tcmb` (default: Turkish central bank, TRY rates since 2005) or `ecb` (European Central Bank, EUR rates since 1999). |
| `start` | query | string | no | YYYY-MM-DD. |
| `end` | query | string | no | YYYY-MM-DD. Default: today. |

**Example**

```bash
curl "https://api.servicebox.io/v1/fx/rates/<code>" \
  -H "Authorization: Bearer $SBX_API_KEY"
```

## Errors

Errors are RFC 9457 `application/problem+json` bodies with a machine-readable `type`.

- `401` — the key is missing, unknown, expired or revoked.
- `402` — not enough credits: the body carries `credits_required` and `upgrade_url` (https://servicebox.io/en/pricing).
- `403` — the key is not allowed to call this API.
- `429` — rate limited: wait `retry_after` seconds (also sent as the `Retry-After` header); `upgrade_url` points to a larger plan.

## Links

- OpenAPI document: https://api.servicebox.io/v1/fx/openapi.json
- Pricing: https://servicebox.io/en/pricing?api=SBX-FX
- API page: https://servicebox.io/en/apis/fx
