Docs / Rates
Convert an amount
Converts an amount between two currencies using one of the published rate sources.
GET
/v1/rates/convertimport { Client } from "@liveapiio/liveapi";
const client = new Client({ token: process.env.LIVEAPI_TOKEN });
const conversion = await client.convert({ from: "USD", to: "TRY", amount: 100, source: "tcmb" });Request
Send Authorization: Bearer YOUR_TOKEN. The token stays on your server. Each library reads it from the environment and calls this endpoint for you.
| Field | Type | Description |
|---|---|---|
| from | string | Source currency code. Required. |
| to | string | Target currency code. Required. |
| amount | number | Amount to convert. Optional. |
| source | string | ecb, fed, or tcmb. Optional. |
| date | string | Calendar day, YYYY-MM-DD. Optional. |
| tcmb_rate | string | forex_buying, forex_selling, banknote_buying, or banknote_selling. Used with the TCMB source. |
Response
A 200 response uses one call. Returns the two currencies, the amount, and the rate that was applied.
Errors
A failed request returns { "error": { "code", "message" } } and does not use a call.
| Status | Code | When |
|---|---|---|
| 400 | invalid_request | A required field is missing or has the wrong type. |
| 503 | upstream_unavailable | The rate source is unavailable. |
| 401 | unauthorized | The bearer token is missing or not recognized. |